bondscell_resultsg$122a00c1-d3d4-43da-b5d1-6bc660f5d43equeued¤logsrunning¦outputbodyْ

If you need both the index and the value of the array element, you can use the enumerate command:

mimetext/htmlrootassigneelast_run_timestampA}*persist_js_state·has_pluto_hook_features§cell_id$122a00c1-d3d4-43da-b5d1-6bc660f5d43edepends_on_disabled_cells§runtimeQpublished_object_keysdepends_on_skipped_cells§errored$f72045aa-fa31-40bf-b80c-5259583f1d30queued¤logsrunning¦outputbodyف

You will see much more of the Distributions.jl package in this course. See also:

mimetext/htmlrootassigneelast_run_timestampA}*o persist_js_state·has_pluto_hook_features§cell_id$f72045aa-fa31-40bf-b80c-5259583f1d30depends_on_disabled_cells§runtimecBpublished_object_keysdepends_on_skipped_cells§errored$ccbf4589-8d25-434e-a7f4-3d972b4ee078queued¤logsrunning¦outputbody1×4 Matrix{Int64}: 1 2 3 4mimetext/plainrootassigneewlast_run_timestampA}*

Packages

The base form of Julia has many wonderful functions and methods. But not everything. To extend functionality, we have to import additional software packages. Below is a list of the few packages we cover in today's tutorial. But you'll see more later in the course.

mimetext/htmlrootassigneelast_run_timestampA}*#Spersist_js_state·has_pluto_hook_features§cell_id$dab1a565-43a9-48ac-896f-cc0ee7856552depends_on_disabled_cells§runtime#published_object_keysdepends_on_skipped_cells§errored$28f3894f-6135-4359-842e-ef5e783fc469queued¤logsrunning¦outputbody

Errors & Debugging

When you call a function that Julia doesn't know, it will return a list of the steps it took to execute your command and point to where its progress was blocked. This is highly useful but it typically requires a bit of practice to parse (i.e., read and filter) stack traces.

MethodError

Suppose we write a function that expects an Integer input and call that function with an Float64 argument:

mimetext/htmlrootassigneelast_run_timestampA}*ưpersist_js_state·has_pluto_hook_features§cell_id$28f3894f-6135-4359-842e-ef5e783fc469depends_on_disabled_cells§runtime ׵published_object_keysdepends_on_skipped_cells§errored$f77783b5-b35a-4437-b436-323d7668d456queued¤logsrunning¦outputbodyٌ

It is possible to add plots to the same figure by using a ! added to your plot command.

mimetext/htmlrootassigneelast_run_timestampA}*persist_js_state·has_pluto_hook_features§cell_id$f77783b5-b35a-4437-b436-323d7668d456depends_on_disabled_cells§runtimeܵpublished_object_keysdepends_on_skipped_cells§errored$8d64ec48-639e-4fc2-9c6c-5cd207c1ba75queued¤logsrunning¦outputbody4mimetext/plainrootassigneelast_run_timestampA}*F3lpersist_js_state·has_pluto_hook_features§cell_id$8d64ec48-639e-4fc2-9c6c-5cd207c1ba75depends_on_disabled_cells§runtime2mpublished_object_keysdepends_on_skipped_cells§errored$6bb76a54-2df8-4604-923a-ebb428eb0353queued¤logsrunning¦outputbody

They can be concatenated by multiplication (which is an example of a function, namely *, which acts differently on different input argument types):

mimetext/htmlrootassigneelast_run_timestampA}*persist_js_state·has_pluto_hook_features§cell_id$6bb76a54-2df8-4604-923a-ebb428eb0353depends_on_disabled_cells§runtimeg^published_object_keysdepends_on_skipped_cells§errored$25c4102b-9ed9-44c7-9c5f-9d7e1810f229queued¤logsrunning¦outputbody%3×2 Matrix{Int64}: 1 1 2 3 3 2mimetext/plainrootassigneelast_run_timestampA}*>C{persist_js_state·has_pluto_hook_features§cell_id$25c4102b-9ed9-44c7-9c5f-9d7e1810f229depends_on_disabled_cells§runtimeʹwpublished_object_keysdepends_on_skipped_cells§errored$28c7a5ed-cbc7-4865-a6a9-b6395ea80a5cqueued¤logsrunning¦outputbodyّ

Stack trace

The stack trace will show you exactly where an error happened.

mimetext/htmlrootassigneelast_run_timestampA}*)persist_js_state·has_pluto_hook_features§cell_id$28c7a5ed-cbc7-4865-a6a9-b6395ea80a5cdepends_on_disabled_cells§runtimeصpublished_object_keysdepends_on_skipped_cells§errored$ec16be17-cdbd-467a-be07-a6fed4e05dadqueued¤logsrunning¦outputbodyB

Julia also has a Symbol type, which is used for meta-programming (not important for this course). A Symbol type is characterized by a : in front of a word. For example:

mimetext/htmlrootassigneelast_run_timestampA}*5persist_js_state·has_pluto_hook_features§cell_id$ec16be17-cdbd-467a-be07-a6fed4e05daddepends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$77271b72-bafe-11f0-8fa2-33da6741b124queued¤logsrunning¦outputbody

This notebook will teach you some of the basic programming routines in Julia. You will need these skills to complete the probabilistic programming assignments later on in the course. We will assume basic familiarity with programming, such as for-loops, if-else statements and function definitions.

Resources:

mimetext/htmlrootassigneelast_run_timestampA}*ưpersist_js_state·has_pluto_hook_features§cell_id$77271b72-bafe-11f0-8fa2-33da6741b124depends_on_disabled_cells§runtime/|published_object_keysdepends_on_skipped_cells§errored$73a811a3-8c64-4bf0-9656-1d8488819f45queued¤logsrunning¦outputbodyٿ

Macros are a somewhat advanced form of metaprogramming. You will not need to define any new macros; this instruction is just here to explain what they are.

mimetext/htmlrootassigneelast_run_timestampA}*hpersist_js_state·has_pluto_hook_features§cell_id$73a811a3-8c64-4bf0-9656-1d8488819f45depends_on_disabled_cells§runtime1Bpublished_object_keysdepends_on_skipped_cells§errored$70a9cd5f-ec47-4c45-b822-64c3ff72322aqueued¤logsrunning¦outputbodyEigen{Float64, Float64, Matrix{Float64}, Vector{Float64}} values: 2-element Vector{Float64}: -0.6853720883753125 4.085372088375313 vectors: 2×2 Matrix{Float64}: 0.476976 -0.878916 -0.878916 -0.476976mimetext/plainrootassigneelast_run_timestampA}*?$ persist_js_state·has_pluto_hook_features§cell_id$70a9cd5f-ec47-4c45-b822-64c3ff72322adepends_on_disabled_cells§runtime\published_object_keysdepends_on_skipped_cells§errored$63530cf1-e20d-4250-a6e0-68443253a0e7queued¤logsrunning¦outputbody} mimeimage/svg+xmlrootassigneelast_run_timestampA}*Dx2persist_js_state·has_pluto_hook_features§cell_id$63530cf1-e20d-4250-a6e0-68443253a0e7depends_on_disabled_cells§runtime]8published_object_keysdepends_on_skipped_cells§errored$400ad142-8fad-42f6-a8cb-3a1b9c56f5dbqueued¤logsrunning¦outputbodyc

Closing

That's it for now. If you encounter mysterious errors, please let us know on Piazza. We can add them to this primer.

And if you have any feedback about improving this short primer on programming in Julia, let us know!

mimetext/htmlrootassigneelast_run_timestampA}*}persist_js_state·has_pluto_hook_features§cell_id$400ad142-8fad-42f6-a8cb-3a1b9c56f5dbdepends_on_disabled_cells§runtime,published_object_keysdepends_on_skipped_cells§errored$4588df60-9c5b-49cc-a3a1-44db790d00edqueued¤logsrunning¦outputbody

Pluto notebooks

The course is built in Pluto.jl, a reactive programming environment. Pluto notebooks are wonderfully intuitive and interactive, and are already revolutionizing mathematics and computer science education (e.g., 18.S191 Computational Thinking @MIT).

A few things to be aware of when working in Pluto notebooks:

mimetext/htmlrootassigneelast_run_timestampA}*apersist_js_state·has_pluto_hook_features§cell_id$4588df60-9c5b-49cc-a3a1-44db790d00eddepends_on_disabled_cells§runtime@Npublished_object_keysdepends_on_skipped_cells§errored$a5a577b6-4266-4698-a3a1-7147590795b5queued¤logsrunning¦outputbodyW

Note that the return argument does not need to be at the end of a function (the return keyword).

You don't actually need the function keyword if you have simple enough functions:

mimetext/htmlrootassigneelast_run_timestampA}*+persist_js_state·has_pluto_hook_features§cell_id$a5a577b6-4266-4698-a3a1-7147590795b5depends_on_disabled_cells§runtime5published_object_keysdepends_on_skipped_cells§errored$ecea873a-ab10-4539-ba66-b05b1ebdf1ecqueued¤logsrunning¦outputbody)

You will not have to use Symbols in the course, but you may see one every once in a while in the lecture notes. For example, the plot command (see Visualization section), may have a markershape=:cross argument.

mimetext/htmlrootassigneelast_run_timestampA}*\Opersist_js_state·has_pluto_hook_features§cell_id$ecea873a-ab10-4539-ba66-b05b1ebdf1ecdepends_on_disabled_cells§runtimeLpublished_object_keysdepends_on_skipped_cells§errored$cf9d6290-0aeb-484a-8816-6972fd3c4891queued¤logsrunning¦outputbodyprefixFloat64elements0.841471text/plain0.909297text/plain0.14112text/plaintypeArrayprefix_shortobjectid3e587709a323ad99mime!application/vnd.pluto.tree+objectrootassigneelast_run_timestampA}*=lp.persist_js_state·has_pluto_hook_features§cell_id$cf9d6290-0aeb-484a-8816-6972fd3c4891depends_on_disabled_cells§runtimeB[published_object_keysdepends_on_skipped_cells§errored$e500c93a-9a4a-4141-819b-051c4e5d5bb0queued¤logsrunning¦outputbodyO

Here is the function used in the last cell:

mimetext/htmlrootassigneelast_run_timestampA}*kpersist_js_state·has_pluto_hook_features§cell_id$e500c93a-9a4a-4141-819b-051c4e5d5bb0depends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$755d9324-5447-4240-9a17-6e212dab4eddqueued¤logsrunning¦outputbody

plot and scatter are the most useful commands. A scatter command will ignore properties such as linewidth and linestyle (since there are no lines) and will listen to markersize and markershape commands (see Supported Attributes in the API).

mimetext/htmlrootassigneelast_run_timestampA}*لpersist_js_state·has_pluto_hook_features§cell_id$755d9324-5447-4240-9a17-6e212dab4edddepends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$3d89c37f-0876-4ba1-aa35-0a7273d4d269queued¤logsrunning¦outputbodyprefixInt64elements1text/plain2text/plain3text/plain4text/plaintypeArrayprefix_shortobjectid3048a8fb84aec90bmime!application/vnd.pluto.tree+objectrootassigneevlast_run_timestampA}*CodeInstance for MethodInstance for give_magic_number(::Int64)inlined£urlpathb/home/runner/work/course/course/probprog/Intro to Julia.jl#==#b6399549-c754-498a-887c-401f252ba21fsource_packagecall>CodeInstance for MethodInstance for give_magic_number(::Int64)linfo_typeCore.CodeInstancelinefile9Intro to Julia.jl#==#b6399549-c754-498a-887c-401f252ba21ffuncgive_magic_numberparent_modulefrom_cŒcall_shortmacro expansioninlinedãurlpathb/home/runner/work/course/course/probprog/Intro to Julia.jl#==#794970ef-f2d2-4dc8-ae43-2b1ecc306a74source_packagecallmacro expansionlinfo_typeNothinglinefile9Intro to Julia.jl#==#794970ef-f2d2-4dc8-ae43-2b1ecc306a74funcmacro expansionparent_modulefrom_c«plain_errorUndefVarError: `kl` not defined in `Main.var"workspace#3"` Suggestion: check for spelling errors or missing imports. Stacktrace: [1] give_magic_number(x::Int64) @ Main.var"workspace#3" ~/work/course/course/probprog/Intro to Julia.jl#==#b6399549-c754-498a-887c-401f252ba21f:4 [2] macro expansion @ ~/work/course/course/probprog/Intro to Julia.jl#==#794970ef-f2d2-4dc8-ae43-2b1ecc306a74:1 [inlined]mime'application/vnd.pluto.stacktrace+objectrootassigneelast_run_timestampA}*Fnpersist_js_state·has_pluto_hook_features§cell_id$794970ef-f2d2-4dc8-ae43-2b1ecc306a74depends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$5905847d-2358-4380-a5a0-c5ac8c716839queued¤logsrunning¦outputbody0.10798193302637613mimetext/plainrootassigneelast_run_timestampA}*ADpersist_js_state·has_pluto_hook_features§cell_id$5905847d-2358-4380-a5a0-c5ac8c716839depends_on_disabled_cells§runtimee?published_object_keysdepends_on_skipped_cells§errored$277c5574-910b-4f05-8661-ef81278e9319queued¤logsrunning¦outputbody

Control flow

Control flow refers to redirecting how a compiler goes through a program. Instead of traversing it line-by-line, things like if-else statements can make a compiler skip steps. These require logical operations: you can use == to check if two variables have the same value, === to check if they are actually the same object (i.e., same memory reference) and != to check if they're not equal.

mimetext/htmlrootassigneelast_run_timestampA}*Qpersist_js_state·has_pluto_hook_features§cell_id$277c5574-910b-4f05-8661-ef81278e9319depends_on_disabled_cells§runtime ;ڵpublished_object_keysdepends_on_skipped_cells§errored$ce73c7c3-5025-4784-8657-b2b67097c702queued¤logsrunning¦outputbody

Functions

Function and expressions are a core component of the julia language. Its "multiple dispatch" feature means that you can define multiple functions with the same name but with behaviour that depends on the input argument types. When you're starting out, you may not notice this so much, but you will start to appreciate this feature tremendously when you begin to professionally develop software.

mimetext/htmlrootassigneelast_run_timestampA}*Wdpersist_js_state·has_pluto_hook_features§cell_id$ce73c7c3-5025-4784-8657-b2b67097c702depends_on_disabled_cells§runtime #4published_object_keysdepends_on_skipped_cells§errored$f5d8574f-b115-4555-8c0e-41f95824740aqueued¤logsrunning¦outputbodyStringmimetext/plainrootassigneelast_run_timestampA}*

// Load the library for consistent smooth scrolling const {default: scrollIntoView} = await import("data:text/javascript;base64,dmFyIFE9ZT0+Im9iamVjdCI9PXR5cGVvZiBlJiZudWxsIT1lJiYxPT09ZS5ub2RlVHlwZSxVPShlLHQpPT4oIXR8fCJoaWRkZW4iIT09ZSkmJiJ2aXNpYmxlIiE9PWUmJiJjbGlwIiE9PWUsQT0oZSx0KT0+e2lmKGUuY2xpZW50SGVpZ2h0PGUuc2Nyb2xsSGVpZ2h0fHxlLmNsaWVudFdpZHRoPGUuc2Nyb2xsV2lkdGgpe2xldCBsPWdldENvbXB1dGVkU3R5bGUoZSxudWxsKTtyZXR1cm4gVShsLm92ZXJmbG93WSx0KXx8VShsLm92ZXJmbG93WCx0KXx8KGU9PntsZXQgdD0oZT0+e2lmKCFlLm93bmVyRG9jdW1lbnR8fCFlLm93bmVyRG9jdW1lbnQuZGVmYXVsdFZpZXcpcmV0dXJuIG51bGw7dHJ5e3JldHVybiBlLm93bmVyRG9jdW1lbnQuZGVmYXVsdFZpZXcuZnJhbWVFbGVtZW50fWNhdGNoe3JldHVybiBudWxsfX0pKGUpO3JldHVybiEhdCYmKHQuY2xpZW50SGVpZ2h0PGUuc2Nyb2xsSGVpZ2h0fHx0LmNsaWVudFdpZHRoPGUuc2Nyb2xsV2lkdGgpfSkoZSl9cmV0dXJuITF9LFg9KGUsdCxsLG8sbixyLGkscyk9PnI8ZSYmaT50fHxyPmUmJmk8dD8wOnI8PWUmJnM8PWx8fGk+PXQmJnM+PWw/ci1lLW86aT50JiZzPGx8fHI8ZSYmcz5sP2ktdCtuOjAsJD1lPT5lLnBhcmVudEVsZW1lbnQ/PyhlLmdldFJvb3ROb2RlKCkuaG9zdHx8bnVsbCksdHQ9KGUsdCk9Pnt2YXIgbCxvLG4scjtpZih0eXBlb2YgZG9jdW1lbnQ+InUiKXJldHVybltdO2xldHtzY3JvbGxNb2RlOmksYmxvY2s6cyxpbmxpbmU6YSxib3VuZGFyeTpoLHNraXBPdmVyZmxvd0hpZGRlbkVsZW1lbnRzOnV9PXQsZz0iZnVuY3Rpb24iPT10eXBlb2YgaD9oOmU9PmUhPT1oO2lmKCFRKGUpKXRocm93IFR5cGVFcnJvcigiSW52YWxpZCB0YXJnZXQiKTtsZXQgdj1kb2N1bWVudC5zY3JvbGxpbmdFbGVtZW50fHxkb2N1bWVudC5kb2N1bWVudEVsZW1lbnQsbT1bXSx3PWU7Zm9yKDtRKHcpJiZnKHcpOyl7aWYoKHc9JCh3KSk9PT12KXttLnB1c2godyk7YnJlYWt9bnVsbCE9dyYmdz09PWRvY3VtZW50LmJvZHkmJkEodykmJiFBKGRvY3VtZW50LmRvY3VtZW50RWxlbWVudCl8fG51bGwhPXcmJkEodyx1KSYmbS5wdXNoKHcpfWxldCBXPW51bGwhPShvPW51bGw9PShsPXdpbmRvdy52aXN1YWxWaWV3cG9ydCk/dm9pZCAwOmwud2lkdGgpP286aW5uZXJXaWR0aCxIPW51bGwhPShyPW51bGw9PShuPXdpbmRvdy52aXN1YWxWaWV3cG9ydCk/dm9pZCAwOm4uaGVpZ2h0KT9yOmlubmVySGVpZ2h0LHtzY3JvbGxYOl8sc2Nyb2xsWTp4fT13aW5kb3cse2hlaWdodDpFLHdpZHRoOlQsdG9wOk4scmlnaHQ6TCxib3R0b206WSxsZWZ0OkN9PWUuZ2V0Qm91bmRpbmdDbGllbnRSZWN0KCksUj0ic3RhcnQiPT09c3x8Im5lYXJlc3QiPT09cz9OOiJlbmQiPT09cz9ZOk4rRS8yLFY9ImNlbnRlciI9PT1hP0MrVC8yOiJlbmQiPT09YT9MOkMsQj1bXTtmb3IobGV0IEQ9MDtEPG0ubGVuZ3RoO0QrKyl7bGV0IE89bVtEXSx7aGVpZ2h0Omosd2lkdGg6SSx0b3A6UyxyaWdodDpxLGJvdHRvbTp6LGxlZnQ6Rn09Ty5nZXRCb3VuZGluZ0NsaWVudFJlY3QoKTtpZigiaWYtbmVlZGVkIj09PWkmJk4+PTAmJkM+PTAmJlk8PUgmJkw8PVcmJk4+PVMmJlk8PXomJkM+PUYmJkw8PXEpYnJlYWs7bGV0IEc9Z2V0Q29tcHV0ZWRTdHlsZShPKSxKPXBhcnNlSW50KEcuYm9yZGVyTGVmdFdpZHRoLDEwKSxLPXBhcnNlSW50KEcuYm9yZGVyVG9wV2lkdGgsMTApLFA9cGFyc2VJbnQoRy5ib3JkZXJSaWdodFdpZHRoLDEwKSxaPXBhcnNlSW50KEcuYm9yZGVyQm90dG9tV2lkdGgsMTApLGVlPTAsZXQ9MCxlbD0ib2Zmc2V0V2lkdGgiaW4gTz9PLm9mZnNldFdpZHRoLU8uY2xpZW50V2lkdGgtSi1QOjAsZW89Im9mZnNldEhlaWdodCJpbiBPP08ub2Zmc2V0SGVpZ2h0LU8uY2xpZW50SGVpZ2h0LUstWjowLGVuPSJvZmZzZXRXaWR0aCJpbiBPPzA9PT1PLm9mZnNldFdpZHRoPzA6SS9PLm9mZnNldFdpZHRoOjAsZXI9Im9mZnNldEhlaWdodCJpbiBPPzA9PT1PLm9mZnNldEhlaWdodD8wOmovTy5vZmZzZXRIZWlnaHQ6MDtpZih2PT09TyllZT0ic3RhcnQiPT09cz9SOiJlbmQiPT09cz9SLUg6Im5lYXJlc3QiPT09cz9YKHgseCtILEgsSyxaLHgrUix4K1IrRSxFKTpSLUgvMixldD0ic3RhcnQiPT09YT9WOiJjZW50ZXIiPT09YT9WLVcvMjoiZW5kIj09PWE/Vi1XOlgoXyxfK1csVyxKLFAsXytWLF8rVitULFQpLGVlPU1hdGgubWF4KDAsZWUreCksZXQ9TWF0aC5tYXgoMCxldCtfKTtlbHNle2VlPSJzdGFydCI9PT1zP1ItUy1LOiJlbmQiPT09cz9SLXorWitlbzoibmVhcmVzdCI9PT1zP1goUyx6LGosSyxaK2VvLFIsUitFLEUpOlItKFMrai8yKStlby8yLGV0PSJzdGFydCI9PT1hP1YtRi1KOiJjZW50ZXIiPT09YT9WLShGK0kvMikrZWwvMjoiZW5kIj09PWE/Vi1xK1ArZWw6WChGLHEsSSxKLFArZWwsVixWK1QsVCk7bGV0e3Njcm9sbExlZnQ6ZWksc2Nyb2xsVG9wOmVkfT1PO2VlPU1hdGgubWF4KDAsTWF0aC5taW4oZWQrZWUvZXIsTy5zY3JvbGxIZWlnaHQtai9lcitlbykpLGV0PU1hdGgubWF4KDAsTWF0aC5taW4oZWkrZXQvZW4sTy5zY3JvbGxXaWR0aC1JL2VuK2VsKSksUis9ZWQtZWUsVis9ZWktZXR9Qi5wdXNoKHtlbDpPLHRvcDplZSxsZWZ0OmV0fSl9cmV0dXJuIEJ9LGY9ZT0+e3ZhciB0O3JldHVybiExPT09ZT97YmxvY2s6ImVuZCIsaW5saW5lOiJuZWFyZXN0In06KHQ9ZSk9PT1PYmplY3QodCkmJjAhPT1PYmplY3Qua2V5cyh0KS5sZW5ndGg/ZTp7YmxvY2s6InN0YXJ0IixpbmxpbmU6Im5lYXJlc3QifX07ZnVuY3Rpb24gYyhlLHQpe3ZhciBsO2lmKCFlLmlzQ29ubmVjdGVkfHwhKGU9PntsZXQgdD1lO2Zvcig7dCYmdC5wYXJlbnROb2RlOyl7aWYodC5wYXJlbnROb2RlPT09ZG9jdW1lbnQpcmV0dXJuITA7dD10LnBhcmVudE5vZGUgaW5zdGFuY2VvZiBTaGFkb3dSb290P3QucGFyZW50Tm9kZS5ob3N0OnQucGFyZW50Tm9kZX1yZXR1cm4hMX0pKGUpKXJldHVybjtpZigib2JqZWN0Ij09dHlwZW9mKGw9dCkmJiJmdW5jdGlvbiI9PXR5cGVvZiBsLmJlaGF2aW9yKXJldHVybiB0LmJlaGF2aW9yKHR0KGUsdCkpO2xldCBvPSJib29sZWFuIj09dHlwZW9mIHR8fG51bGw9PXQ/dm9pZCAwOnQuYmVoYXZpb3I7Zm9yKGxldHtlbDpuLHRvcDpyLGxlZnQ6aX1vZiB0dChlLGYodCkpKW4uc2Nyb2xsKHt0b3A6cixsZWZ0OmksYmVoYXZpb3I6b30pfXZhciBkLHA9KCk9PihkfHwoZD0icGVyZm9ybWFuY2UiaW4gd2luZG93P3BlcmZvcm1hbmNlLm5vdy5iaW5kKHBlcmZvcm1hbmNlKTpEYXRlLm5vdyksZCgpKTtmdW5jdGlvbiBiKGUpe2xldCB0PU1hdGgubWluKChwKCktZS5zdGFydFRpbWUpL2UuZHVyYXRpb24sMSksbD1lLmVhc2UodCksbz1lLnN0YXJ0WCsoZS54LWUuc3RhcnRYKSpsLG49ZS5zdGFydFkrKGUueS1lLnN0YXJ0WSkqbDtlLm1ldGhvZChvLG4sdCxsKSxvIT09ZS54fHxuIT09ZS55P3JlcXVlc3RBbmltYXRpb25GcmFtZSgoKT0+YihlKSk6ZS5jYigpfWZ1bmN0aW9uIHkoZSx0LGwpe2xldCBvPWFyZ3VtZW50cy5sZW5ndGg+MyYmdm9pZCAwIT09YXJndW1lbnRzWzNdP2FyZ3VtZW50c1szXTo2MDAsbj1hcmd1bWVudHMubGVuZ3RoPjQmJnZvaWQgMCE9PWFyZ3VtZW50c1s0XT9hcmd1bWVudHNbNF06ZT0+MSstLWUqZSplKmUqZSxyPWFyZ3VtZW50cy5sZW5ndGg+NT9hcmd1bWVudHNbNV06dm9pZCAwLGk9YXJndW1lbnRzLmxlbmd0aD42P2FyZ3VtZW50c1s2XTp2b2lkIDAscz1lLnNjcm9sbExlZnQsYT1lLnNjcm9sbFRvcDtiKHtzY3JvbGxhYmxlOmUsbWV0aG9kKHQsbCxvLG4pe2xldCByPU1hdGguY2VpbCh0KSxzPU1hdGguY2VpbChsKTtlLnNjcm9sbExlZnQ9cixlLnNjcm9sbFRvcD1zLGk/Lih7dGFyZ2V0OmUsZWxhcHNlZDpvLHZhbHVlOm4sbGVmdDpyLHRvcDpzfSl9LHN0YXJ0VGltZTpwKCksc3RhcnRYOnMsc3RhcnRZOmEseDp0LHk6bCxkdXJhdGlvbjpvLGVhc2U6bixjYjpyfSl9dmFyIE09ZT0+ZSYmIWUuYmVoYXZpb3J8fCJzbW9vdGgiPT09ZS5iZWhhdmlvcixrPWZ1bmN0aW9uKGUsdCl7bGV0IGw9dHx8e307cmV0dXJuIE0obCk/YyhlLHtibG9jazpsLmJsb2NrLGlubGluZTpsLmlubGluZSxzY3JvbGxNb2RlOmwuc2Nyb2xsTW9kZSxib3VuZGFyeTpsLmJvdW5kYXJ5LHNraXBPdmVyZmxvd0hpZGRlbkVsZW1lbnRzOmwuc2tpcE92ZXJmbG93SGlkZGVuRWxlbWVudHMsYmVoYXZpb3I6ZT0+UHJvbWlzZS5hbGwoZS5yZWR1Y2UoKGUsdCk9PntsZXR7ZWw6byxsZWZ0Om4sdG9wOnJ9PXQsaT1vLnNjcm9sbExlZnQscz1vLnNjcm9sbFRvcDtyZXR1cm4gaT09PW4mJnM9PT1yP2U6Wy4uLmUsbmV3IFByb21pc2UoZT0+eShvLG4scixsLmR1cmF0aW9uLGwuZWFzZSwoKT0+ZSh7ZWw6byxsZWZ0OltpLG5dLHRvcDpbcyxyXX0pLGwub25TY3JvbGxDaGFuZ2UpKV19LFtdKSl9KTpQcm9taXNlLnJlc29sdmUoYyhlLHQpKX07ZXhwb3J0e2sgYXMgZGVmYXVsdH07") const indent = true const aside = true const title_text = "Table of Contents" const include_definitions = false const tocNode = html`

` tocNode.classList.toggle("aside", aside) tocNode.classList.toggle("indent", indent) const getParentCell = el => el.closest("pluto-cell") const getHeaders = () => { const depth = Math.max(1, Math.min(6, 3)) // should be in range 1:6 const range = Array.from({length: depth}, (x, i) => i+1) // [1, ..., depth] const selector = [ ...(include_definitions ? [ `pluto-notebook pluto-cell .pluto-docs-binding`, `pluto-notebook pluto-cell assignee:not(:empty)`, ] : []), ...range.map(i => `pluto-notebook pluto-cell h${i}`) ].join(",") return Array.from(document.querySelectorAll(selector)).filter(el => // exclude headers inside of a pluto-docs-binding block !(el.nodeName.startsWith("H") && el.closest(".pluto-docs-binding")) && !el.classList.contains("no-toc") ) } const document_click_handler = (event) => { const path = (event.path || event.composedPath()) const toc = path.find(elem => elem?.classList?.contains?.("toc-toggle")) if (toc) { event.stopImmediatePropagation() toc.closest(".plutoui-toc").classList.toggle("hide") } } document.addEventListener("click", document_click_handler) const header_to_index_entry_map = new Map() const currently_highlighted_set = new Set() const last_toc_element_click_time = { current: 0 } const intersection_callback = (ixs) => { let on_top = ixs.filter(ix => ix.intersectionRatio > 0 && ix.intersectionRect.y < ix.rootBounds.height / 2) if(on_top.length > 0){ currently_highlighted_set.forEach(a => a.classList.remove("in-view")) currently_highlighted_set.clear() on_top.slice(0,1).forEach(i => { let div = header_to_index_entry_map.get(i.target) div.classList.add("in-view") currently_highlighted_set.add(div) /// scroll into view /* const toc_height = tocNode.offsetHeight const div_pos = div.offsetTop const div_height = div.offsetHeight const current_scroll = tocNode.scrollTop const header_height = tocNode.querySelector("header").offsetHeight const scroll_to_top = div_pos - header_height const scroll_to_bottom = div_pos + div_height - toc_height // if we set a scrollTop, then the browser will stop any currently ongoing smoothscroll animation. So let's only do this if you are not currently in a smoothscroll. if(Date.now() - last_toc_element_click_time.current >= 2000) if(current_scroll < scroll_to_bottom){ tocNode.scrollTop = scroll_to_bottom } else if(current_scroll > scroll_to_top){ tocNode.scrollTop = scroll_to_top } */ }) } } let intersection_observer_1 = new IntersectionObserver(intersection_callback, { root: null, // i.e. the viewport threshold: 1, rootMargin: "-15px", // slightly smaller than the viewport // delay: 100, }) let intersection_observer_2 = new IntersectionObserver(intersection_callback, { root: null, // i.e. the viewport threshold: 1, rootMargin: "15px", // slightly larger than the viewport // delay: 100, }) const render = (elements) => { header_to_index_entry_map.clear() currently_highlighted_set.clear() intersection_observer_1.disconnect() intersection_observer_2.disconnect() let last_level = `H1` return html`${elements.map(h => { const parent_cell = getParentCell(h) let [className, title_el] = h.matches(`.pluto-docs-binding`) ? ["pluto-docs-binding-el", h.firstElementChild] : [h.nodeName, h] const id = title_el.matches("assignee") ? title_el.innerText.replace(/^const /, "") : title_el.id ? title_el.id : parent_cell.id const inner_html = title_el.innerHTML const a = html`${inner_html}` /* a.onmouseover=()=>{ parent_cell.firstElementChild.classList.add( 'highlight-pluto-cell-shoulder' ) } a.onmouseout=() => { parent_cell.firstElementChild.classList.remove( 'highlight-pluto-cell-shoulder' ) } */ a.onclick=(e) => { e.preventDefault(); history.replaceState(null, null, a.href) last_toc_element_click_time.current = Date.now() scrollIntoView(h, { behavior: 'smooth', block: 'start', }).then(() => // sometimes it doesn't scroll to the right place // solution: try a second time! scrollIntoView(h, { behavior: 'smooth', block: 'start', }) ) } // Remove any `id` attributes recursively, because they may interfere with linking-to-id using `#` const removeIdAttributes = (el) => { if (el && el.nodeType === 1) { // Element node if (el.hasAttribute?.("id")) el.removeAttribute?.("id") el.childNodes.forEach(removeIdAttributes) } } removeIdAttributes(a) // Remove Click-To-Copy-Header-ID feature a.querySelectorAll("pluto-header-id-copy-wrapper").forEach(el => el.remove()) const row = html`
${a}
` intersection_observer_1.observe(title_el) intersection_observer_2.observe(title_el) header_to_index_entry_map.set(title_el, row) if(className.startsWith("H")) last_level = className return row })}` } const invalidated = { current: false } const updateCallback = () => { if (!invalidated.current) { tocNode.querySelector("section").replaceWith( html`
${render(getHeaders())}
` ) } } updateCallback() setTimeout(updateCallback, 100) setTimeout(updateCallback, 1000) setTimeout(updateCallback, 5000) const notebook = document.querySelector("pluto-notebook") // We have a mutationobserver for each cell: const mut_observers = { current: [], } const createCellObservers = () => { mut_observers.current.forEach((o) => o.disconnect()) mut_observers.current = Array.from(notebook.querySelectorAll("pluto-cell")).map(el => { const o = new MutationObserver(updateCallback) o.observe(el, {attributeFilter: ["class"]}) return o }) } createCellObservers() // And one for the notebook's child list, which updates our cell observers: const notebookObserver = new MutationObserver(() => { updateCallback() createCellObservers() }) notebookObserver.observe(notebook, {childList: true}) // And finally, an observer for the document.body classList, to make sure that the toc also works when it is loaded during notebook initialization const bodyClassObserver = new MutationObserver(updateCallback) bodyClassObserver.observe(document.body, {attributeFilter: ["class"]}) // Hide/show the ToC when the screen gets small let match_listener = () => { const small = (tocNode.closest("pluto-editor") ?? document.body).scrollWidth < 1000 tocNode.classList.toggle("smallscreen", small) tocNode.classList.toggle("hide", small) } for(let s of [1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000]) { let m = matchMedia(`(max-width: ${s}px)`) m.addListener(match_listener) invalidation.then(() => m.removeListener(match_listener)) } match_listener() invalidation.then(() => { invalidated.current = true intersection_observer_1.disconnect() intersection_observer_2.disconnect() notebookObserver.disconnect() bodyClassObserver.disconnect() mut_observers.current.forEach((o) => o.disconnect()) document.removeEventListener("click", document_click_handler) }) return tocNode mimetext/htmlrootassigneelast_run_timestampA}*;persist_js_state·has_pluto_hook_features§cell_id$705dedd6-755f-4a18-9d4d-cde8c9755e05depends_on_disabled_cells§runtime21published_object_keysdepends_on_skipped_cells§errored$034f3378-6dc8-4fff-b8a7-afdc330b4f01queued¤logslinemsg1, 0text/plaincell_id$034f3378-6dc8-4fff-b8a7-afdc330b4f01kwargsidMain_workspace#2_5abb3ea5fileb/home/runner/work/course/course/probprog/Intro to Julia.jl#==#034f3378-6dc8-4fff-b8a7-afdc330b4f01groupIntro to JulialevelInfolinemsg2, 1text/plaincell_id$034f3378-6dc8-4fff-b8a7-afdc330b4f01kwargsidMain_workspace#2_5abb3ea5fileb/home/runner/work/course/course/probprog/Intro to Julia.jl#==#034f3378-6dc8-4fff-b8a7-afdc330b4f01groupIntro to JulialevelInfolinemsg3, 2text/plaincell_id$034f3378-6dc8-4fff-b8a7-afdc330b4f01kwargsidMain_workspace#2_5abb3ea5fileb/home/runner/work/course/course/probprog/Intro to Julia.jl#==#034f3378-6dc8-4fff-b8a7-afdc330b4f01groupIntro to JulialevelInfolinemsg4, 3text/plaincell_id$034f3378-6dc8-4fff-b8a7-afdc330b4f01kwargsidMain_workspace#2_5abb3ea5fileb/home/runner/work/course/course/probprog/Intro to Julia.jl#==#034f3378-6dc8-4fff-b8a7-afdc330b4f01groupIntro to JulialevelInforunning¦outputbodymimetext/plainrootassigneelast_run_timestampA}*=!persist_js_state·has_pluto_hook_features§cell_id$034f3378-6dc8-4fff-b8a7-afdc330b4f01depends_on_disabled_cells§runtimef$published_object_keysdepends_on_skipped_cells§errored$61f5260a-dd5b-4ca1-9d55-30d7fd453f4equeued¤logsrunning¦outputbody"Positive"mimetext/plainrootassigneelast_run_timestampA}*=Spersist_js_state·has_pluto_hook_features§cell_id$61f5260a-dd5b-4ca1-9d55-30d7fd453f4edepends_on_disabled_cells§runtime͙=published_object_keysdepends_on_skipped_cells§errored$83e2a97e-72d7-404e-b138-f2c5d30d6365queued¤logsrunning¦outputbody"ab"mimetext/plainrootassigneeablast_run_timestampA}*

You may be familiar with "list comprehension", which is a shortened form of iterating through a collection:

mimetext/htmlrootassigneelast_run_timestampA}*|persist_js_state·has_pluto_hook_features§cell_id$408e3447-21bb-4617-bdf2-d60f7cfb8ecedepends_on_disabled_cells§runtimel}published_object_keysdepends_on_skipped_cells§errored$e608d8a8-8faa-4302-bf7e-ae135cef47a4queued¤logsrunning¦outputbodyFloat64mimetext/plainrootassigneelast_run_timestampA}*<\0˰persist_js_state·has_pluto_hook_features§cell_id$e608d8a8-8faa-4302-bf7e-ae135cef47a4depends_on_disabled_cells§runtime/published_object_keysdepends_on_skipped_cells§errored$e47bad96-4092-4d0a-8035-f05310359565queued¤logsrunning¦outputbody

Broadcasting

You can apply functions to elements in an array by placing a dot in front:

mimetext/htmlrootassigneelast_run_timestampA}*⹰persist_js_state·has_pluto_hook_features§cell_id$e47bad96-4092-4d0a-8035-f05310359565depends_on_disabled_cells§runtimeXpublished_object_keysdepends_on_skipped_cells§errored$f5df9bc3-79df-4e0b-b199-9ade76f53894queued¤logsrunning¦outputbodyInt64mimetext/plainrootassigneelast_run_timestampA}*<+A[persist_js_state·has_pluto_hook_features§cell_id$f5df9bc3-79df-4e0b-b199-9ade76f53894depends_on_disabled_cells§runtime:published_object_keysdepends_on_skipped_cells§errored$be6f2317-24c7-470c-bde8-233ad3d6f3bdqueued¤logsrunning¦outputbodyprefixInt64elements4text/plain7text/plain8text/plaintypeArrayprefix_shortobjectidfd6bf1ce271be915mime!application/vnd.pluto.tree+objectrootassigneelast_run_timestampA}*=3#Ͱpersist_js_state·has_pluto_hook_features§cell_id$be6f2317-24c7-470c-bde8-233ad3d6f3bddepends_on_disabled_cells§runtimelpublished_object_keysdepends_on_skipped_cells§errored$767a5b82-b007-42aa-897c-6dfa4eadf28aqueued¤logsrunning¦outputbodyH

This also works for named functions:

mimetext/htmlrootassigneelast_run_timestampA}*persist_js_state·has_pluto_hook_features§cell_id$767a5b82-b007-42aa-897c-6dfa4eadf28adepends_on_disabled_cells§runtime˵published_object_keysdepends_on_skipped_cells§errored$58b280bc-914e-45e2-bae4-3c767ba09ec3queued¤logsrunning¦outputbodym

Matrix operations are intuitive and similar to the mathematical notation:

mimetext/htmlrootassigneelast_run_timestampA}*)аpersist_js_state·has_pluto_hook_features§cell_id$58b280bc-914e-45e2-bae4-3c767ba09ec3depends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$a02297a2-8660-4fd1-95af-438f363b9f29queued¤logsrunning¦outputbodyprefixStringelements"n = 2"text/plain"n = 3"text/plain"n = 4"text/plaintypeArrayprefix_shortobjectid44b38293ab2b3ec7mime!application/vnd.pluto.tree+objectrootassigneelast_run_timestampA}*=persist_js_state·has_pluto_hook_features§cell_id$a02297a2-8660-4fd1-95af-438f363b9f29depends_on_disabled_cells§runtimeipublished_object_keysdepends_on_skipped_cells§errored$02c03dad-d974-4584-9766-0e7ea79047e0queued¤logsrunning¦outputbodyI

Data types

Numbers in Julia have specific types, most notably Integer, Real and Complex. (See this documentation page for the full type tree.) It is important to be aware of what type your numbers are because many functions operate differently on different number types.

mimetext/htmlrootassigneelast_run_timestampA}*2persist_js_state·has_pluto_hook_features§cell_id$02c03dad-d974-4584-9766-0e7ea79047e0depends_on_disabled_cells§runtime:published_object_keysdepends_on_skipped_cells§errored$721d9bd7-c04c-4874-897e-61fde49ba257queued¤logsrunning¦outputbody#fn (generic function with 1 method)mimetext/plainrootassigneelast_run_timestampA}*=y[persist_js_state·has_pluto_hook_features§cell_id$721d9bd7-c04c-4874-897e-61fde49ba257depends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$14e2c87f-557e-45fa-8036-464d5b4deac5queued¤logsrunning¦outputbodyٮ

You should read this as "there exists a function called add1 that expects an Integer input." Try that.

mimetext/htmlrootassigneelast_run_timestampA}*persist_js_state·has_pluto_hook_features§cell_id$14e2c87f-557e-45fa-8036-464d5b4deac5depends_on_disabled_cells§runtime published_object_keysdepends_on_skipped_cells§errored$3e1ca65e-f4cc-4d28-8139-f04d70980ecbqueued¤logsrunning¦outputbody3.0mimetext/plainrootassigneeblast_run_timestampA}*<9persist_js_state·has_pluto_hook_features§cell_id$3e1ca65e-f4cc-4d28-8139-f04d70980ecbdepends_on_disabled_cells§runtime7opublished_object_keysdepends_on_skipped_cells§errored$e5555433-b323-4af5-805c-db592461307bqueued¤logsrunning¦outputbody

Mathced types in MethodError

The red highlighting of ::Integer is also important but requires a slightly more complicated example. Suppose we have a function with two Integer inputs and we call with Float64 and Int64 arguments.

mimetext/htmlrootassigneelast_run_timestampA}*Ipersist_js_state·has_pluto_hook_features§cell_id$e5555433-b323-4af5-805c-db592461307bdepends_on_disabled_cells§runtimePpublished_object_keysdepends_on_skipped_cells§errored$881a67da-5f59-437d-91ce-8c8113985fb6queued¤logsrunning¦outputbodymimetext/plainrootassigneelast_run_timestampA}*2Qpersist_js_state·has_pluto_hook_features§cell_id$90d21b8f-b29b-420c-894b-a94abb52f2bbdepends_on_disabled_cells§runtime+published_object_keysdepends_on_skipped_cells§errored$9d9799b0-2e0c-4180-ae80-44e5c268c8b4queued¤logsrunning¦outputbody3mimetext/plainrootassigneealast_run_timestampA}*;9persist_js_state·has_pluto_hook_features§cell_id$9d9799b0-2e0c-4180-ae80-44e5c268c8b4depends_on_disabled_cells§runtime0published_object_keysdepends_on_skipped_cells§errored$9f761389-7125-4df0-877f-9925b315913fqueued¤logsrunning¦outputbodyx

Below are some examples of importing packages and using their added functionalities.

mimetext/htmlrootassigneelast_run_timestampA}*Ipersist_js_state·has_pluto_hook_features§cell_id$9f761389-7125-4df0-877f-9925b315913fdepends_on_disabled_cells§runtimeŒpublished_object_keysdepends_on_skipped_cells§errored$897d515d-bfda-4a8f-abbb-9276d69f0f4dqueued¤logsrunning¦outputbodymsgtMethodError: no method matching add1(::Float64) The function `add1` exists, but no method is defined for this combination of argument types. Closest candidates are:  add1(::Integer)  @ Main.var"workspace#3" ~/work/course/course/probprog/Intro to Julia.jl#==#113fa658-4325-4ea6-a5ab-6337889006f4:1 stacktracecall_shortmacro expansioninlinedãurlpathb/home/runner/work/course/course/probprog/Intro to Julia.jl#==#897d515d-bfda-4a8f-abbb-9276d69f0f4dsource_packagecallmacro expansionlinfo_typeNothinglinefile9Intro to Julia.jl#==#897d515d-bfda-4a8f-abbb-9276d69f0f4dfuncmacro expansionparent_modulefrom_c«plain_errorMethodError: no method matching add1(::Float64) The function `add1` exists, but no method is defined for this combination of argument types. Closest candidates are: add1(!Matched::Integer) @ Main.var"workspace#3" ~/work/course/course/probprog/Intro to Julia.jl#==#113fa658-4325-4ea6-a5ab-6337889006f4:1 Stacktrace: [1] macro expansion @ ~/work/course/course/probprog/Intro to Julia.jl#==#897d515d-bfda-4a8f-abbb-9276d69f0f4d:1 [inlined]mime'application/vnd.pluto.stacktrace+objectrootassigneelast_run_timestampA}*F1persist_js_state·has_pluto_hook_features§cell_id$897d515d-bfda-4a8f-abbb-9276d69f0f4ddepends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$ebbf4498-4082-44a0-a904-c80ca6dab2c7queued¤logsrunning¦outputbody$1×2 Matrix{Float64}: 1.0 0.333333mimetext/plainrootassigneelast_run_timestampA}*>7&persist_js_state·has_pluto_hook_features§cell_id$ebbf4498-4082-44a0-a904-c80ca6dab2c7depends_on_disabled_cells§runtimeHipublished_object_keysdepends_on_skipped_cells§errored$2bad907d-5859-4465-8ed6-4285642d9874queued¤logsrunning¦outputbody

Note that we first of all get a MethodError. This points to the fact that Julia could not find the function (i.e, method) that you asked for; add1(::Float64) does not exist.

Furthermore, Julia provides a list of "Closest candidates" which are functions of the same name with different input arguments. It reports:

mimetext/htmlrootassigneelast_run_timestampA}*Жpersist_js_state·has_pluto_hook_features§cell_id$2bad907d-5859-4465-8ed6-4285642d9874depends_on_disabled_cells§runtime0͵published_object_keysdepends_on_skipped_cells§errored$660571c4-3d5e-4eba-b6d9-bcab17c2a2eequeued¤logsrunning¦outputbodyProgramming in Juliamimetext/htmlrootassigneelast_run_timestampA}*;'persist_js_state·has_pluto_hook_features§cell_id$660571c4-3d5e-4eba-b6d9-bcab17c2a2eedepends_on_disabled_cells§runtime͗published_object_keysdepends_on_skipped_cells§errored$4f785723-2f6a-4dcd-82a7-8d15daf191e8queued¤logsrunning¦outputbodyJ

What to do with errors?

To summarize, when you get an error, it is important to take your time, and read the message. If you want to know where something happened, look at the stack trace. Try to see an error message as positive feedback: you are on the right track, and Julia is trying to help you to write the correct code.

The type of error can also be informative. The MethodError is probably the error you will see most often.

mimetext/htmlrootassigneelast_run_timestampA}*꯰persist_js_state·has_pluto_hook_features§cell_id$4f785723-2f6a-4dcd-82a7-8d15daf191e8depends_on_disabled_cells§runtime еpublished_object_keysdepends_on_skipped_cells§errored$51123db8-3fdf-4497-b121-ce5b989bc063queued¤logsrunning¦outputbodyo

You can incorporate numbers into strings through a $ call:

mimetext/htmlrootassigneelast_run_timestampA}* (persist_js_state·has_pluto_hook_features§cell_id$51123db8-3fdf-4497-b121-ce5b989bc063depends_on_disabled_cells§runtime;published_object_keysdepends_on_skipped_cells§errored$c66b8dec-aa58-4508-9f93-70d65ba2c051queued¤logsrunning¦outputbody

We again get the MethodError that the function we asked for doesn't exist and a suggested alternative (i.e., "closest candidate"). But this time, only the first argument ::Integer is highlighted in red.

Julia checks your input argument types against those in the closest candidates. This tells you what to change: the solution would be to either:

  • Change the call: Make the first argument of your function call to an Integer type. That would be add(3, 4).

  • Change the defintion: Make the function accept a more general Real number as the first argument.

mimetext/htmlrootassigneelast_run_timestampA}*persist_js_state·has_pluto_hook_features§cell_id$c66b8dec-aa58-4508-9f93-70d65ba2c051depends_on_disabled_cells§runtimelpublished_object_keysdepends_on_skipped_cells§errored$895960bf-1ee2-4aa8-b38c-5857525b1ddcqueued¤logsrunning¦outputbodyz

Matrices can be constructed by separating elements with spaces and rows by semicolons:

mimetext/htmlrootassigneelast_run_timestampA}*/persist_js_state·has_pluto_hook_features§cell_id$895960bf-1ee2-4aa8-b38c-5857525b1ddcdepends_on_disabled_cells§runtimeCpublished_object_keysdepends_on_skipped_cells§errored$08b24136-c292-4360-a90e-a8fd82d45d6bqueued¤logsrunning¦outputbody$add (generic function with 1 method)mimetext/plainrootassigneelast_run_timestampA}*F?Ȱpersist_js_state·has_pluto_hook_features§cell_id$08b24136-c292-4360-a90e-a8fd82d45d6bdepends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$e3be7db2-a307-4083-bb35-db4e70dfe1bfqueued¤logsrunning¦outputbodyj

Visualization

Plots.jl provides a common interface to call various other visualization backends (GR, Matplotlib, PGFPlotsX, Plotly, etc.). In other words, commands like plot(..) will be translated into the appropriate command for the backend. So, it does not re-invent the wheel but rather gives you access to the already enormous field of visualization tools.

Below are a few examples of the most common visualization commands you'll see throughout the course. The core principle is to use a plot type as base command and then provide keyword arguments (in String, Number or Symbol type) to apply variations.

mimetext/htmlrootassigneelast_run_timestampA}*Opersist_js_state·has_pluto_hook_features§cell_id$e3be7db2-a307-4083-bb35-db4e70dfe1bfdepends_on_disabled_cells§runtime ޵published_object_keysdepends_on_skipped_cells§errored$3b0e1194-e6df-46e4-8c41-032f5beeb8faqueued¤logsrunning¦outputbody

You can add keyword arguments to a function, which are input arguments with default values:

mimetext/htmlrootassigneelast_run_timestampA}*\persist_js_state·has_pluto_hook_features§cell_id$3b0e1194-e6df-46e4-8c41-032f5beeb8fadepends_on_disabled_cells§runtime. published_object_keysdepends_on_skipped_cells§errored$7bc7fb04-9d74-4970-b06b-5bc95d7be757queued¤logsrunning¦outputbodyk

Strings are constructed by enclosing symbols within double parentheses.

mimetext/htmlrootassigneelast_run_timestampA}*persist_js_state·has_pluto_hook_features§cell_id$7bc7fb04-9d74-4970-b06b-5bc95d7be757depends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$6b4c2d62-b1d0-4f42-9ee6-eb2d9f8ba98aqueued¤logsrunning¦outputbodyFloat64mimetext/plainrootassigneelast_run_timestampA}* mimeimage/svg+xmlrootassigneelast_run_timestampA}*DFpersist_js_state·has_pluto_hook_features§cell_id$909a83f1-507c-4d8f-855e-f1a45d3aa927depends_on_disabled_cells§runtimeMpublished_object_keysdepends_on_skipped_cells§errored$de01ba69-cc44-4f3a-8dfa-98f4a194b28aqueued¤logsrunning¦outputbody

Macros

Words that start with the @ symbol are macros in Julia, for example @time, @test, @model. They represent a series of functions called on an input structure and are really handy when you have to use the same set of instructions often.

For example, you could define a ProgressMeter bar, update it at every iteration of a for-loop and write a custom print statement every time. Or, you could call the @showprogress macro on the for-loop itself:

mimetext/htmlrootassigneelast_run_timestampA}*Bpersist_js_state·has_pluto_hook_features§cell_id$de01ba69-cc44-4f3a-8dfa-98f4a194b28adepends_on_disabled_cells§runtime published_object_keysdepends_on_skipped_cells§errored$6969d1e5-38d0-432d-842e-153139f86613queued¤logsrunning¦outputbody"e = 3"mimetext/plainrootassigneelast_run_timestampA}*

But if I call the sort! function and the original vector, you'll see that the original vector is now also sorted.

mimetext/htmlrootassigneelast_run_timestampA}*persist_js_state·has_pluto_hook_features§cell_id$a520e936-d80b-42fe-9b45-28d972383ff9depends_on_disabled_cells§runtimeopublished_object_keysdepends_on_skipped_cells§errored$0103d1f6-ea03-4497-a0de-e1b0c181d648queued¤logsrunning¦outputbodymimetext/plainrootassigneelast_run_timestampA}*|persist_js_state·has_pluto_hook_features§cell_id$0103d1f6-ea03-4497-a0de-e1b0c181d648depends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$5e402035-3a17-4072-8288-cbc613bc4cbaqueued¤logsrunning¦outputbodyb
Closest candidates are:
  add1(::Integer)
mimetext/htmlrootassigneelast_run_timestampA}*F2{lpersist_js_state·has_pluto_hook_features§cell_id$5e402035-3a17-4072-8288-cbc613bc4cbadepends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$6048a5ad-2964-4aab-a708-32754e52eb1cqueued¤logsrunning¦outputbodyo mimeimage/svg+xmlrootassigneelast_run_timestampA}*DTpersist_js_state·has_pluto_hook_features§cell_id$6048a5ad-2964-4aab-a708-32754e52eb1cdepends_on_disabled_cells§runtimeΎmpublished_object_keysdepends_on_skipped_cells§errored$d2d811d0-9e38-4fc6-b576-3156309b3715queued¤logsrunning¦outputbody-3.0:0.02:3.0mimetext/plainrootassigneexxlast_run_timestampA}*Apersist_js_state·has_pluto_hook_features§cell_id$d2d811d0-9e38-4fc6-b576-3156309b3715depends_on_disabled_cells§runtimePpublished_object_keysdepends_on_skipped_cells§errored$66a29ea6-d467-4909-964d-c88d68da4d50queued¤logsrunning¦outputbody

Simple if-else statements can often be replaced by ternary checks. Essentially, you ask a question (a logical operation followed by ?) and then tell the program what to do when the answer is yes (written immediately after the question) or no (written after the yes-answer followed by a :).

mimetext/htmlrootassigneelast_run_timestampA}*persist_js_state·has_pluto_hook_features§cell_id$66a29ea6-d467-4909-964d-c88d68da4d50depends_on_disabled_cells§runtime&published_object_keysdepends_on_skipped_cells§errored$44add801-211a-423d-9279-54ab6a101420queued¤logsrunning¦outputbody`

Functions that modify their input arguments instead of creating new output variables are typically marked with an !. Below I have defined an unsorted vector and I call sort to sort it in increasing order. If I call the sort function and the original vector, then they will be different:

mimetext/htmlrootassigneelast_run_timestampA}*persist_js_state·has_pluto_hook_features§cell_id$44add801-211a-423d-9279-54ab6a101420depends_on_disabled_cells§runtimeϵpublished_object_keysdepends_on_skipped_cells§errored$bfbfe9cf-9a28-4b52-8c50-4ab9965a6288queued¤logsrunning¦outputbody10×2 Matrix{Float64}: -2.54265 0.427514 0.343613 -0.251879 -0.0671576 -1.44463 -0.961886 0.376192 0.688295 -0.0421418 -0.956101 0.230085 -1.63937 -0.258495 0.817772 -0.531188 -1.27945 1.77312 -0.741292 -0.288236mimetext/plainrootassigneeXlast_run_timestampA}*DY߰persist_js_state·has_pluto_hook_features§cell_id$bfbfe9cf-9a28-4b52-8c50-4ab9965a6288depends_on_disabled_cells§runtimeVŵpublished_object_keysdepends_on_skipped_cells§errored$29f6c7eb-69ba-4072-a77d-7097235c1dacqueued¤logsrunning¦outputbody

Int64 is a 64-byte integer. Other options are 32-,16-, or 8-bit integers and they can be unsigned as well. The default real-valued numbers is a 64-bit floating-point number:

mimetext/htmlrootassigneelast_run_timestampA}*Y%persist_js_state·has_pluto_hook_features§cell_id$29f6c7eb-69ba-4072-a77d-7097235c1dacdepends_on_disabled_cells§runtimew"published_object_keysdepends_on_skipped_cells§errored$5d627a4e-5dee-4c25-b99c-ae7e4221109fqueued¤logsrunning¦outputbodyD

Converting number types is easy:

mimetext/htmlrootassigneelast_run_timestampA}*~persist_js_state·has_pluto_hook_features§cell_id$5d627a4e-5dee-4c25-b99c-ae7e4221109fdepends_on_disabled_cells§runtimevpublished_object_keysdepends_on_skipped_cells§errored$77f5b5de-040f-4406-bb57-c1fe58e3b32bqueued¤logsrunning¦outputbody

Array manipulation

Arrays are indexed with square brackets, A[i,j]. You can construct a matrix by enclosing a set of numbers with square brackets. If you separate your numbers with comma's, then you will get a column vector:

mimetext/htmlrootassigneelast_run_timestampA}*[persist_js_state·has_pluto_hook_features§cell_id$77f5b5de-040f-4406-bb57-c1fe58e3b32bdepends_on_disabled_cells§runtime +published_object_keysdepends_on_skipped_cells§errored$0e341cb6-bbca-4581-858f-50b4e2ca858aqueued¤logsrunning¦outputbodymsgMethodError: no method matching add(::Float64, ::Int64) The function `add` exists, but no method is defined for this combination of argument types. Closest candidates are:  add(::Integer, ::Integer)  @ Main.var"workspace#3" ~/work/course/course/probprog/Intro to Julia.jl#==#08b24136-c292-4360-a90e-a8fd82d45d6b:1 stacktracecall_shortmacro expansioninlinedãurlpathb/home/runner/work/course/course/probprog/Intro to Julia.jl#==#0e341cb6-bbca-4581-858f-50b4e2ca858asource_packagecallmacro expansionlinfo_typeNothinglinefile9Intro to Julia.jl#==#0e341cb6-bbca-4581-858f-50b4e2ca858afuncmacro expansionparent_modulefrom_c«plain_errorMethodError: no method matching add(::Float64, ::Int64) The function `add` exists, but no method is defined for this combination of argument types. Closest candidates are: add(!Matched::Integer, ::Integer) @ Main.var"workspace#3" ~/work/course/course/probprog/Intro to Julia.jl#==#08b24136-c292-4360-a90e-a8fd82d45d6b:1 Stacktrace: [1] macro expansion @ ~/work/course/course/probprog/Intro to Julia.jl#==#0e341cb6-bbca-4581-858f-50b4e2ca858a:1 [inlined]mime'application/vnd.pluto.stacktrace+objectrootassigneelast_run_timestampA}*FA?persist_js_state·has_pluto_hook_features§cell_id$0e341cb6-bbca-4581-858f-50b4e2ca858adepends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$54662c5d-7ba3-4e96-88ce-3c9ba1907f8equeued¤logsrunning¦outputbody7

For example, the cell below contains a mistake and evaluating it will throw an error. But which line has the mistake? Press the Show stack trace... button or Show more... to see the stack trace of the error below. Where did the error happen?

mimetext/htmlrootassigneelast_run_timestampA}*Xpersist_js_state·has_pluto_hook_features§cell_id$54662c5d-7ba3-4e96-88ce-3c9ba1907f8edepends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$7a1e8d0a-cffc-497a-88a7-fd9757bc8edaqueued¤logsrunning¦outputbody:foomimetext/plainrootassigneeflast_run_timestampA}*

Common array constructors are:

mimetext/htmlrootassigneelast_run_timestampA}*persist_js_state·has_pluto_hook_features§cell_id$519dbc40-2c83-4fda-b6fe-d3547b43b407depends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$f4753dd6-51f7-48db-b8e9-26b550af1bacqueued¤logsrunning¦outputbody%3×2 Matrix{Int64}: 0 0 1 1 2 2mimetext/plainrootassigneelast_run_timestampA}*>Eèpersist_js_state·has_pluto_hook_features§cell_id$f4753dd6-51f7-48db-b8e9-26b550af1bacdepends_on_disabled_cells§runtimeNԵpublished_object_keysdepends_on_skipped_cells§errored$0d8059ae-c158-43f2-81a8-9cba2f667177queued¤logsrunning¦outputbodyي

If you use spaces, then you will construct a row vector (i.e., a matrix of dimensions 1 by n):

mimetext/htmlrootassigneelast_run_timestampA}*persist_js_state·has_pluto_hook_features§cell_id$0d8059ae-c158-43f2-81a8-9cba2f667177depends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$c97780c0-c60f-443d-98c8-100e67576e23queued¤logsrunning¦outputbody

A matrix can be transposed by a single parenthesis, A'. Note that this does not mutate the array in memory. It just tells functions defined for matrices that it should change how it indexes the matrix's elements.

mimetext/htmlrootassigneelast_run_timestampA}*P+persist_js_state·has_pluto_hook_features§cell_id$c97780c0-c60f-443d-98c8-100e67576e23depends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$8a606467-0434-418f-85e5-40a35c9df95fqueued¤logsrunning¦outputbodyrows1text/plain2text/plain3text/plainobjectid7ccbca39a9d6cf9aschemanamesabctypesInt64Int64Int64mime"application/vnd.pluto.table+objectrootassigneelast_run_timestampA}*@persist_js_state·has_pluto_hook_features§cell_id$8a606467-0434-418f-85e5-40a35c9df95fdepends_on_disabled_cells§runtimeDupublished_object_keysdepends_on_skipped_cells§errored$ff063276-46ef-4768-a0b1-878e9eb1a13equeued¤logsrunning¦outputbody

Next, we can use the range command to construct an array of numbers and then use the in command to loop over elements in the array:

mimetext/htmlrootassigneelast_run_timestampA}*apersist_js_state·has_pluto_hook_features§cell_id$ff063276-46ef-4768-a0b1-878e9eb1a13edepends_on_disabled_cells§runtime_cpublished_object_keysdepends_on_skipped_cells§errored$96b831a8-09ba-4792-8268-14c368b804f8queued¤logsrunning¦outputbody2×2 Matrix{Int64}: 1 2 3 4mimetext/plainrootassigneeMlast_run_timestampA}*

Iteration

For-loops are one of the simplest forms of iteration and can be defined in a number of ways. First, the matlab way:

mimetext/htmlrootassigneelast_run_timestampA}*=persist_js_state·has_pluto_hook_features§cell_id$2e3b7a55-a85b-4498-8dc4-c14853ec06abdepends_on_disabled_cells§runtimeSpublished_object_keysdepends_on_skipped_cells§errored$14ab0808-3fdb-4113-8854-43255987a006queued¤logsrunning¦outputbody3.0mimetext/plainrootassigneeclast_run_timestampA}*<[e persist_js_state·has_pluto_hook_features§cell_id$14ab0808-3fdb-4113-8854-43255987a006depends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$eacafc14-d0f6-472f-be69-2ab0d81e41b1queued¤logsrunning¦outputbody 

Mini: Distributions in Julia

Introduction to working with Distributions and Plots in Julia.

mimetext/htmlrootassigneelast_run_timestampA}*Aj4npersist_js_state·has_pluto_hook_features§cell_id$eacafc14-d0f6-472f-be69-2ab0d81e41b1depends_on_disabled_cells§runtime7E\published_object_keysdepends_on_skipped_cells§errored±cell_dependenciesg$122a00c1-d3d4-43da-b5d1-6bc660f5d43eprecedence_heuristic cell_id$122a00c1-d3d4-43da-b5d1-6bc660f5d43edownstream_cells_mapupstream_cells_map@md_strgetindex$f72045aa-fa31-40bf-b80c-5259583f1d30precedence_heuristic cell_id$f72045aa-fa31-40bf-b80c-5259583f1d30downstream_cells_mapupstream_cells_map@md_strgetindex$ccbf4589-8d25-434e-a7f4-3d972b4ee078precedence_heuristic cell_id$ccbf4589-8d25-434e-a7f4-3d972b4ee078downstream_cells_mapwupstream_cells_map$3889c64c-d018-4c04-80a4-246aaede7d4eprecedence_heuristic cell_id$3889c64c-d018-4c04-80a4-246aaede7d4edownstream_cells_mapfooupstream_cells_mapFloat64Integer$dab1a565-43a9-48ac-896f-cc0ee7856552precedence_heuristic cell_id$dab1a565-43a9-48ac-896f-cc0ee7856552downstream_cells_mapupstream_cells_map@md_strgetindex$28f3894f-6135-4359-842e-ef5e783fc469precedence_heuristic cell_id$28f3894f-6135-4359-842e-ef5e783fc469downstream_cells_mapupstream_cells_map@md_strgetindex$f77783b5-b35a-4437-b436-323d7668d456precedence_heuristic cell_id$f77783b5-b35a-4437-b436-323d7668d456downstream_cells_mapupstream_cells_map@md_strgetindex$8d64ec48-639e-4fc2-9c6c-5cd207c1ba75precedence_heuristic cell_id$8d64ec48-639e-4fc2-9c6c-5cd207c1ba75downstream_cells_mapupstream_cells_mapadd1$113fa658-4325-4ea6-a5ab-6337889006f4$6bb76a54-2df8-4604-923a-ebb428eb0353precedence_heuristic cell_id$6bb76a54-2df8-4604-923a-ebb428eb0353downstream_cells_mapupstream_cells_map@md_strgetindex$25c4102b-9ed9-44c7-9c5f-9d7e1810f229precedence_heuristic cell_id$25c4102b-9ed9-44c7-9c5f-9d7e1810f229downstream_cells_mapeupstream_cells_mapsort$28c7a5ed-cbc7-4865-a6a9-b6395ea80a5cprecedence_heuristic cell_id$28c7a5ed-cbc7-4865-a6a9-b6395ea80a5cdownstream_cells_mapupstream_cells_map@md_strgetindex$ec16be17-cdbd-467a-be07-a6fed4e05dadprecedence_heuristic cell_id$ec16be17-cdbd-467a-be07-a6fed4e05daddownstream_cells_mapupstream_cells_map@md_strgetindex$77271b72-bafe-11f0-8fa2-33da6741b124precedence_heuristic cell_id$77271b72-bafe-11f0-8fa2-33da6741b124downstream_cells_mapupstream_cells_map@md_strgetindex$73a811a3-8c64-4bf0-9656-1d8488819f45precedence_heuristic cell_id$73a811a3-8c64-4bf0-9656-1d8488819f45downstream_cells_mapupstream_cells_map@md_strgetindex$70a9cd5f-ec47-4c45-b822-64c3ff72322aprecedence_heuristic cell_id$70a9cd5f-ec47-4c45-b822-64c3ff72322adownstream_cells_mapupstream_cells_mapeigen$63530cf1-e20d-4250-a6e0-68443253a0e7precedence_heuristic cell_id$63530cf1-e20d-4250-a6e0-68443253a0e7downstream_cells_mapupstream_cells_map:X$bfbfe9cf-9a28-4b52-8c50-4ab9965a6288scatter$400ad142-8fad-42f6-a8cb-3a1b9c56f5dbprecedence_heuristic cell_id$400ad142-8fad-42f6-a8cb-3a1b9c56f5dbdownstream_cells_mapupstream_cells_map@md_strgetindex$4588df60-9c5b-49cc-a3a1-44db790d00edprecedence_heuristic cell_id$4588df60-9c5b-49cc-a3a1-44db790d00eddownstream_cells_mapupstream_cells_map@md_strgetindex$a5a577b6-4266-4698-a3a1-7147590795b5precedence_heuristic cell_id$a5a577b6-4266-4698-a3a1-7147590795b5downstream_cells_mapupstream_cells_map@md_strgetindex$ecea873a-ab10-4539-ba66-b05b1ebdf1ecprecedence_heuristic cell_id$ecea873a-ab10-4539-ba66-b05b1ebdf1ecdownstream_cells_mapupstream_cells_map@md_strgetindex$cf9d6290-0aeb-484a-8816-6972fd3c4891precedence_heuristic cell_id$cf9d6290-0aeb-484a-8816-6972fd3c4891downstream_cells_mapupstream_cells_mapsin$e500c93a-9a4a-4141-819b-051c4e5d5bb0precedence_heuristic cell_id$e500c93a-9a4a-4141-819b-051c4e5d5bb0downstream_cells_mapupstream_cells_map@md_strgetindex$755d9324-5447-4240-9a17-6e212dab4eddprecedence_heuristic cell_id$755d9324-5447-4240-9a17-6e212dab4edddownstream_cells_mapupstream_cells_map@md_strgetindex$3d89c37f-0876-4ba1-aa35-0a7273d4d269precedence_heuristic cell_id$3d89c37f-0876-4ba1-aa35-0a7273d4d269downstream_cells_mapvupstream_cells_map$794970ef-f2d2-4dc8-ae43-2b1ecc306a74precedence_heuristic cell_id$794970ef-f2d2-4dc8-ae43-2b1ecc306a74downstream_cells_mapupstream_cells_mapgive_magic_number$b6399549-c754-498a-887c-401f252ba21f$5905847d-2358-4380-a5a0-c5ac8c716839precedence_heuristic cell_id$5905847d-2358-4380-a5a0-c5ac8c716839downstream_cells_mappx$6048a5ad-2964-4aab-a708-32754e52eb1cupstream_cells_mappdfNormal$277c5574-910b-4f05-8661-ef81278e9319precedence_heuristic cell_id$277c5574-910b-4f05-8661-ef81278e9319downstream_cells_mapupstream_cells_map@md_strgetindex$ce73c7c3-5025-4784-8657-b2b67097c702precedence_heuristic cell_id$ce73c7c3-5025-4784-8657-b2b67097c702downstream_cells_mapupstream_cells_map@md_strgetindex$f5d8574f-b115-4555-8c0e-41f95824740aprecedence_heuristic cell_id$f5d8574f-b115-4555-8c0e-41f95824740adownstream_cells_mapupstream_cells_maptypeofd$5013d835-99b7-4b08-bc97-8085017d47ab$d5a8ec92-a4fa-46e6-983c-44572a74f886precedence_heuristiccell_id$d5a8ec92-a4fa-46e6-983c-44572a74f886downstream_cells_mapLinearAlgebraDistributionsPlotsBmlipTeachingToolsDataFramesProgressMeter$b3e11050-b799-4d88-b5cc-bc9d057be7bcupstream_cells_map$9dc43526-5604-4251-aa22-3aff5fa3bd0bprecedence_heuristic cell_id$9dc43526-5604-4251-aa22-3aff5fa3bd0bdownstream_cells_mapfn$90d21b8f-b29b-420c-894b-a94abb52f2bb$ebbf4498-4082-44a0-a904-c80ca6dab2c7upstream_cells_map/Number$705dedd6-755f-4a18-9d4d-cde8c9755e05precedence_heuristic cell_id$705dedd6-755f-4a18-9d4d-cde8c9755e05downstream_cells_mapupstream_cells_mapTableOfContents$034f3378-6dc8-4fff-b8a7-afdc330b4f01precedence_heuristic cell_id$034f3378-6dc8-4fff-b8a7-afdc330b4f01downstream_cells_mapupstream_cells_mapBase.CoreLogging.invokelatestBase.CoreLogging.===Base.throw#___this_pluto_module_name'Base.CoreLogging.Base.fixup_stdlib_pathBase.CoreLogging.!BaseenumerateBase.CoreLogging.isarange@infoBase.invokelatestBase.CoreLogging.>=Base.AssertionError$61f5260a-dd5b-4ca1-9d55-30d7fd453f4eprecedence_heuristic cell_id$61f5260a-dd5b-4ca1-9d55-30d7fd453f4edownstream_cells_mapr$826ef035-bf26-45ac-b33c-dc2dcaa23f7cupstream_cells_map=Base.AssertionError$8fe19ca9-6618-4c70-8eca-6ba002630ca9precedence_heuristic cell_id$8fe19ca9-6618-4c70-8eca-6ba002630ca9downstream_cells_mapupstream_cells_mapadd$08b24136-c292-4360-a90e-a8fd82d45d6b$408e3447-21bb-4617-bdf2-d60f7cfb8eceprecedence_heuristic cell_id$408e3447-21bb-4617-bdf2-d60f7cfb8ecedownstream_cells_mapupstream_cells_map@md_strgetindex$e608d8a8-8faa-4302-bf7e-ae135cef47a4precedence_heuristic cell_id$e608d8a8-8faa-4302-bf7e-ae135cef47a4downstream_cells_mapupstream_cells_mapc$14ab0808-3fdb-4113-8854-43255987a006typeof$e47bad96-4092-4d0a-8035-f05310359565precedence_heuristic cell_id$e47bad96-4092-4d0a-8035-f05310359565downstream_cells_mapupstream_cells_map@md_strgetindex$f5df9bc3-79df-4e0b-b199-9ade76f53894precedence_heuristic cell_id$f5df9bc3-79df-4e0b-b199-9ade76f53894downstream_cells_mapupstream_cells_maptypeofa$9d9799b0-2e0c-4180-ae80-44e5c268c8b4$be6f2317-24c7-470c-bde8-233ad3d6f3bdprecedence_heuristic cell_id$be6f2317-24c7-470c-bde8-233ad3d6f3bddownstream_cells_mapA$174612aa-d8a0-4a21-be83-91648dac1f61x$174612aa-d8a0-4a21-be83-91648dac1f61$f4753dd6-51f7-48db-b8e9-26b550af1bacupstream_cells_map*$767a5b82-b007-42aa-897c-6dfa4eadf28aprecedence_heuristic cell_id$767a5b82-b007-42aa-897c-6dfa4eadf28adownstream_cells_mapupstream_cells_map@md_strgetindex$58b280bc-914e-45e2-bae4-3c767ba09ec3precedence_heuristic cell_id$58b280bc-914e-45e2-bae4-3c767ba09ec3downstream_cells_mapupstream_cells_map@md_strgetindex$a02297a2-8660-4fd1-95af-438f363b9f29precedence_heuristic cell_id$a02297a2-8660-4fd1-95af-438f363b9f29downstream_cells_mapupstream_cells_maprange$02c03dad-d974-4584-9766-0e7ea79047e0precedence_heuristic cell_id$02c03dad-d974-4584-9766-0e7ea79047e0downstream_cells_mapupstream_cells_map@md_strgetindex$721d9bd7-c04c-4874-897e-61fde49ba257precedence_heuristic cell_id$721d9bd7-c04c-4874-897e-61fde49ba257downstream_cells_mapfn$90d21b8f-b29b-420c-894b-a94abb52f2bb$ebbf4498-4082-44a0-a904-c80ca6dab2c7upstream_cells_map/Number$14e2c87f-557e-45fa-8036-464d5b4deac5precedence_heuristic cell_id$14e2c87f-557e-45fa-8036-464d5b4deac5downstream_cells_mapupstream_cells_map@md_strgetindex$3e1ca65e-f4cc-4d28-8139-f04d70980ecbprecedence_heuristic cell_id$3e1ca65e-f4cc-4d28-8139-f04d70980ecbdownstream_cells_mapb$6b4c2d62-b1d0-4f42-9ee6-eb2d9f8ba98aupstream_cells_map$e5555433-b323-4af5-805c-db592461307bprecedence_heuristic cell_id$e5555433-b323-4af5-805c-db592461307bdownstream_cells_mapupstream_cells_map@md_strBase.getindexBaseBase.Docs.HTML@html_str$881a67da-5f59-437d-91ce-8c8113985fb6precedence_heuristic cell_id$881a67da-5f59-437d-91ce-8c8113985fb6downstream_cells_mapUWVupstream_cells_maprandnzerosones$b6399549-c754-498a-887c-401f252ba21fprecedence_heuristic cell_id$b6399549-c754-498a-887c-401f252ba21fdownstream_cells_mapgive_magic_number$794970ef-f2d2-4dc8-ae43-2b1ecc306a74upstream_cells_mapkl*Real$90d21b8f-b29b-420c-894b-a94abb52f2bbprecedence_heuristic cell_id$90d21b8f-b29b-420c-894b-a94abb52f2bbdownstream_cells_mapupstream_cells_mapfn$721d9bd7-c04c-4874-897e-61fde49ba257$9dc43526-5604-4251-aa22-3aff5fa3bd0b$9d9799b0-2e0c-4180-ae80-44e5c268c8b4precedence_heuristic cell_id$9d9799b0-2e0c-4180-ae80-44e5c268c8b4downstream_cells_mapa$f5df9bc3-79df-4e0b-b199-9ade76f53894$6969d1e5-38d0-432d-842e-153139f86613upstream_cells_map$9f761389-7125-4df0-877f-9925b315913fprecedence_heuristic cell_id$9f761389-7125-4df0-877f-9925b315913fdownstream_cells_mapupstream_cells_map@md_strgetindex$897d515d-bfda-4a8f-abbb-9276d69f0f4dprecedence_heuristic cell_id$897d515d-bfda-4a8f-abbb-9276d69f0f4ddownstream_cells_mapupstream_cells_mapadd1$113fa658-4325-4ea6-a5ab-6337889006f4$ebbf4498-4082-44a0-a904-c80ca6dab2c7precedence_heuristic cell_id$ebbf4498-4082-44a0-a904-c80ca6dab2c7downstream_cells_mapupstream_cells_mapfn$721d9bd7-c04c-4874-897e-61fde49ba257$9dc43526-5604-4251-aa22-3aff5fa3bd0b$2bad907d-5859-4465-8ed6-4285642d9874precedence_heuristic cell_id$2bad907d-5859-4465-8ed6-4285642d9874downstream_cells_mapupstream_cells_map@md_strgetindex$660571c4-3d5e-4eba-b6d9-bcab17c2a2eeprecedence_heuristic cell_id$660571c4-3d5e-4eba-b6d9-bcab17c2a2eedownstream_cells_mapupstream_cells_maptitle$4f785723-2f6a-4dcd-82a7-8d15daf191e8precedence_heuristic cell_id$4f785723-2f6a-4dcd-82a7-8d15daf191e8downstream_cells_mapupstream_cells_map@md_strgetindex$51123db8-3fdf-4497-b121-ce5b989bc063precedence_heuristic cell_id$51123db8-3fdf-4497-b121-ce5b989bc063downstream_cells_mapupstream_cells_map@md_strgetindex$c66b8dec-aa58-4508-9f93-70d65ba2c051precedence_heuristic cell_id$c66b8dec-aa58-4508-9f93-70d65ba2c051downstream_cells_mapupstream_cells_map@md_strBase.getindexBaseBase.Docs.HTML@html_str$895960bf-1ee2-4aa8-b38c-5857525b1ddcprecedence_heuristic cell_id$895960bf-1ee2-4aa8-b38c-5857525b1ddcdownstream_cells_mapupstream_cells_map@md_strgetindex$08b24136-c292-4360-a90e-a8fd82d45d6bprecedence_heuristic cell_id$08b24136-c292-4360-a90e-a8fd82d45d6bdownstream_cells_mapadd$0e341cb6-bbca-4581-858f-50b4e2ca858a$8fe19ca9-6618-4c70-8eca-6ba002630ca9upstream_cells_map+Integer$e3be7db2-a307-4083-bb35-db4e70dfe1bfprecedence_heuristic cell_id$e3be7db2-a307-4083-bb35-db4e70dfe1bfdownstream_cells_mapupstream_cells_map@md_strgetindex$3b0e1194-e6df-46e4-8c41-032f5beeb8faprecedence_heuristic cell_id$3b0e1194-e6df-46e4-8c41-032f5beeb8fadownstream_cells_mapupstream_cells_map@md_strgetindex$7bc7fb04-9d74-4970-b06b-5bc95d7be757precedence_heuristic cell_id$7bc7fb04-9d74-4970-b06b-5bc95d7be757downstream_cells_mapupstream_cells_map@md_strgetindex$6b4c2d62-b1d0-4f42-9ee6-eb2d9f8ba98aprecedence_heuristic cell_id$6b4c2d62-b1d0-4f42-9ee6-eb2d9f8ba98adownstream_cells_mapupstream_cells_mapb$3e1ca65e-f4cc-4d28-8139-f04d70980ecbtypeof$826ef035-bf26-45ac-b33c-dc2dcaa23f7cprecedence_heuristic cell_id$826ef035-bf26-45ac-b33c-dc2dcaa23f7cdownstream_cells_mapupstream_cells_map<>islessr$61f5260a-dd5b-4ca1-9d55-30d7fd453f4e$909a83f1-507c-4d8f-855e-f1a45d3aa927precedence_heuristic cell_id$909a83f1-507c-4d8f-855e-f1a45d3aa927downstream_cells_mapupstream_cells_mappdfxx$d2d811d0-9e38-4fc6-b576-3156309b3715plotplot!Normal$de01ba69-cc44-4f3a-8dfa-98f4a194b28aprecedence_heuristic cell_id$de01ba69-cc44-4f3a-8dfa-98f4a194b28adownstream_cells_mapupstream_cells_map@md_strgetindex$6969d1e5-38d0-432d-842e-153139f86613precedence_heuristic cell_id$6969d1e5-38d0-432d-842e-153139f86613downstream_cells_mapupstream_cells_mapa$9d9799b0-2e0c-4180-ae80-44e5c268c8b4$5013d835-99b7-4b08-bc97-8085017d47abprecedence_heuristic cell_id$5013d835-99b7-4b08-bc97-8085017d47abdownstream_cells_mapd$f5d8574f-b115-4555-8c0e-41f95824740aupstream_cells_map$ab9f639a-abd0-44e0-bb89-ed27472a641dprecedence_heuristic cell_id$ab9f639a-abd0-44e0-bb89-ed27472a641ddownstream_cells_mapupstream_cells_map*$2f5ff4dc-5267-4d64-aca5-a6a0be536f8fprecedence_heuristic cell_id$2f5ff4dc-5267-4d64-aca5-a6a0be536f8fdownstream_cells_mapupstream_cells_mapCoreBase.CoreLogging.invokelatestBase.CoreLogging.===Core.UndefVarErrorBase.throw#___this_pluto_module_name'Base.CoreLogging.Base.fixup_stdlib_pathBase.CoreLogging.!BaseBase.CoreLogging.isarange@infoBase.invokelatestBase.CoreLogging.>=Base.AssertionError$8ebd00be-c361-4080-b1a6-8eca643439a5precedence_heuristic cell_id$8ebd00be-c361-4080-b1a6-8eca643439a5downstream_cells_mapupstream_cells_mapf$7a1e8d0a-cffc-497a-88a7-fd9757bc8edatypeof$174612aa-d8a0-4a21-be83-91648dac1f61precedence_heuristic cell_id$174612aa-d8a0-4a21-be83-91648dac1f61downstream_cells_mapupstream_cells_mapA$be6f2317-24c7-470c-bde8-233ad3d6f3bdx$be6f2317-24c7-470c-bde8-233ad3d6f3bd*adjointconj$113fa658-4325-4ea6-a5ab-6337889006f4precedence_heuristic cell_id$113fa658-4325-4ea6-a5ab-6337889006f4downstream_cells_mapadd1$897d515d-bfda-4a8f-abbb-9276d69f0f4d$8d64ec48-639e-4fc2-9c6c-5cd207c1ba75upstream_cells_map+Integer$a520e936-d80b-42fe-9b45-28d972383ff9precedence_heuristic cell_id$a520e936-d80b-42fe-9b45-28d972383ff9downstream_cells_mapupstream_cells_map@md_strgetindex$0103d1f6-ea03-4497-a0de-e1b0c181d648precedence_heuristic cell_id$0103d1f6-ea03-4497-a0de-e1b0c181d648downstream_cells_mapupstream_cells_map$5e402035-3a17-4072-8288-cbc613bc4cbaprecedence_heuristic cell_id$5e402035-3a17-4072-8288-cbc613bc4cbadownstream_cells_mapupstream_cells_mapHypertextLiteral.BypassHypertextLiteral.ResultHypertextLiteral@htl$6048a5ad-2964-4aab-a708-32754e52eb1cprecedence_heuristic cell_id$6048a5ad-2964-4aab-a708-32754e52eb1cdownstream_cells_mapupstream_cells_mappdfxx$d2d811d0-9e38-4fc6-b576-3156309b3715plotpx$5905847d-2358-4380-a5a0-c5ac8c716839$d2d811d0-9e38-4fc6-b576-3156309b3715precedence_heuristic cell_id$d2d811d0-9e38-4fc6-b576-3156309b3715downstream_cells_mapxx$6048a5ad-2964-4aab-a708-32754e52eb1c$909a83f1-507c-4d8f-855e-f1a45d3aa927upstream_cells_maprange$66a29ea6-d467-4909-964d-c88d68da4d50precedence_heuristic cell_id$66a29ea6-d467-4909-964d-c88d68da4d50downstream_cells_mapupstream_cells_map@md_strgetindex$44add801-211a-423d-9279-54ab6a101420precedence_heuristic cell_id$44add801-211a-423d-9279-54ab6a101420downstream_cells_mapupstream_cells_map@md_strgetindex$bfbfe9cf-9a28-4b52-8c50-4ab9965a6288precedence_heuristic cell_id$bfbfe9cf-9a28-4b52-8c50-4ab9965a6288downstream_cells_mapX$63530cf1-e20d-4250-a6e0-68443253a0e7upstream_cells_maprandn$29f6c7eb-69ba-4072-a77d-7097235c1dacprecedence_heuristic cell_id$29f6c7eb-69ba-4072-a77d-7097235c1dacdownstream_cells_mapupstream_cells_map@md_strgetindex$5d627a4e-5dee-4c25-b99c-ae7e4221109fprecedence_heuristic cell_id$5d627a4e-5dee-4c25-b99c-ae7e4221109fdownstream_cells_mapupstream_cells_map@md_strgetindex$77f5b5de-040f-4406-bb57-c1fe58e3b32bprecedence_heuristic cell_id$77f5b5de-040f-4406-bb57-c1fe58e3b32bdownstream_cells_mapupstream_cells_map@md_strgetindex$0e341cb6-bbca-4581-858f-50b4e2ca858aprecedence_heuristic cell_id$0e341cb6-bbca-4581-858f-50b4e2ca858adownstream_cells_mapupstream_cells_mapadd$08b24136-c292-4360-a90e-a8fd82d45d6b$54662c5d-7ba3-4e96-88ce-3c9ba1907f8eprecedence_heuristic cell_id$54662c5d-7ba3-4e96-88ce-3c9ba1907f8edownstream_cells_mapupstream_cells_map@md_strgetindex$7a1e8d0a-cffc-497a-88a7-fd9757bc8edaprecedence_heuristic cell_id$7a1e8d0a-cffc-497a-88a7-fd9757bc8edadownstream_cells_mapf$8ebd00be-c361-4080-b1a6-8eca643439a5upstream_cells_map$b3e11050-b799-4d88-b5cc-bc9d057be7bcprecedence_heuristic cell_id$b3e11050-b799-4d88-b5cc-bc9d057be7bcdownstream_cells_map#547#iterable##meter#281upstream_cells_mapProgressMeter.lengthsleep:ProgressMeter.ProgressWrapperProgressMeter.Progress@showprogressProgressMeter$d5a8ec92-a4fa-46e6-983c-44572a74f886$519dbc40-2c83-4fda-b6fe-d3547b43b407precedence_heuristic cell_id$519dbc40-2c83-4fda-b6fe-d3547b43b407downstream_cells_mapupstream_cells_map@md_strgetindex$f4753dd6-51f7-48db-b8e9-26b550af1bacprecedence_heuristic cell_id$f4753dd6-51f7-48db-b8e9-26b550af1bacdownstream_cells_mapupstream_cells_mapsort!x$be6f2317-24c7-470c-bde8-233ad3d6f3bd$0d8059ae-c158-43f2-81a8-9cba2f667177precedence_heuristic cell_id$0d8059ae-c158-43f2-81a8-9cba2f667177downstream_cells_mapupstream_cells_map@md_strgetindex$c97780c0-c60f-443d-98c8-100e67576e23precedence_heuristic cell_id$c97780c0-c60f-443d-98c8-100e67576e23downstream_cells_mapupstream_cells_map@md_strgetindex$8a606467-0434-418f-85e5-40a35c9df95fprecedence_heuristic cell_id$8a606467-0434-418f-85e5-40a35c9df95fdownstream_cells_mapdfDupstream_cells_mapDictDataFrame=>$ff063276-46ef-4768-a0b1-878e9eb1a13eprecedence_heuristic cell_id$ff063276-46ef-4768-a0b1-878e9eb1a13edownstream_cells_mapupstream_cells_map@md_strgetindex$96b831a8-09ba-4792-8268-14c368b804f8precedence_heuristic cell_id$96b831a8-09ba-4792-8268-14c368b804f8downstream_cells_mapMupstream_cells_map$2e3b7a55-a85b-4498-8dc4-c14853ec06abprecedence_heuristic cell_id$2e3b7a55-a85b-4498-8dc4-c14853ec06abdownstream_cells_mapupstream_cells_map@md_strgetindex$14ab0808-3fdb-4113-8854-43255987a006precedence_heuristic cell_id$14ab0808-3fdb-4113-8854-43255987a006downstream_cells_mapc$e608d8a8-8faa-4302-bf7e-ae135cef47a4upstream_cells_mapconvertFloat64$eacafc14-d0f6-472f-be69-2ab0d81e41b1precedence_heuristic cell_id$eacafc14-d0f6-472f-be69-2ab0d81e41b1downstream_cells_mapupstream_cells_mapNotebookCardcell_execution_orderg$d5a8ec92-a4fa-46e6-983c-44572a74f886$660571c4-3d5e-4eba-b6d9-bcab17c2a2ee$77271b72-bafe-11f0-8fa2-33da6741b124$705dedd6-755f-4a18-9d4d-cde8c9755e05$02c03dad-d974-4584-9766-0e7ea79047e0$9d9799b0-2e0c-4180-ae80-44e5c268c8b4$f5df9bc3-79df-4e0b-b199-9ade76f53894$29f6c7eb-69ba-4072-a77d-7097235c1dac$3e1ca65e-f4cc-4d28-8139-f04d70980ecb$6b4c2d62-b1d0-4f42-9ee6-eb2d9f8ba98a$5d627a4e-5dee-4c25-b99c-ae7e4221109f$14ab0808-3fdb-4113-8854-43255987a006$e608d8a8-8faa-4302-bf7e-ae135cef47a4$0103d1f6-ea03-4497-a0de-e1b0c181d648$7bc7fb04-9d74-4970-b06b-5bc95d7be757$5013d835-99b7-4b08-bc97-8085017d47ab$f5d8574f-b115-4555-8c0e-41f95824740a$6bb76a54-2df8-4604-923a-ebb428eb0353$83e2a97e-72d7-404e-b138-f2c5d30d6365$51123db8-3fdf-4497-b121-ce5b989bc063$6969d1e5-38d0-432d-842e-153139f86613$ec16be17-cdbd-467a-be07-a6fed4e05dad$7a1e8d0a-cffc-497a-88a7-fd9757bc8eda$8ebd00be-c361-4080-b1a6-8eca643439a5$ecea873a-ab10-4539-ba66-b05b1ebdf1ec$77f5b5de-040f-4406-bb57-c1fe58e3b32b$3d89c37f-0876-4ba1-aa35-0a7273d4d269$0d8059ae-c158-43f2-81a8-9cba2f667177$ccbf4589-8d25-434e-a7f4-3d972b4ee078$895960bf-1ee2-4aa8-b38c-5857525b1ddc$96b831a8-09ba-4792-8268-14c368b804f8$519dbc40-2c83-4fda-b6fe-d3547b43b407$881a67da-5f59-437d-91ce-8c8113985fb6$58b280bc-914e-45e2-bae4-3c767ba09ec3$be6f2317-24c7-470c-bde8-233ad3d6f3bd$c97780c0-c60f-443d-98c8-100e67576e23$174612aa-d8a0-4a21-be83-91648dac1f61$4588df60-9c5b-49cc-a3a1-44db790d00ed$e47bad96-4092-4d0a-8035-f05310359565$ab9f639a-abd0-44e0-bb89-ed27472a641d$767a5b82-b007-42aa-897c-6dfa4eadf28a$cf9d6290-0aeb-484a-8816-6972fd3c4891$2e3b7a55-a85b-4498-8dc4-c14853ec06ab$cc21a0ab-d413-453b-94a0-15d33524ca4f$ff063276-46ef-4768-a0b1-878e9eb1a13e$2f5ff4dc-5267-4d64-aca5-a6a0be536f8f$122a00c1-d3d4-43da-b5d1-6bc660f5d43e$034f3378-6dc8-4fff-b8a7-afdc330b4f01$408e3447-21bb-4617-bdf2-d60f7cfb8ece$a02297a2-8660-4fd1-95af-438f363b9f29$277c5574-910b-4f05-8661-ef81278e9319$61f5260a-dd5b-4ca1-9d55-30d7fd453f4e$66a29ea6-d467-4909-964d-c88d68da4d50$826ef035-bf26-45ac-b33c-dc2dcaa23f7c$ce73c7c3-5025-4784-8657-b2b67097c702$3889c64c-d018-4c04-80a4-246aaede7d4e$a5a577b6-4266-4698-a3a1-7147590795b5$721d9bd7-c04c-4874-897e-61fde49ba257$3b0e1194-e6df-46e4-8c41-032f5beeb8fa$9dc43526-5604-4251-aa22-3aff5fa3bd0b$90d21b8f-b29b-420c-894b-a94abb52f2bb$ebbf4498-4082-44a0-a904-c80ca6dab2c7$44add801-211a-423d-9279-54ab6a101420$25c4102b-9ed9-44c7-9c5f-9d7e1810f229$a520e936-d80b-42fe-9b45-28d972383ff9$f4753dd6-51f7-48db-b8e9-26b550af1bac$dab1a565-43a9-48ac-896f-cc0ee7856552$9f761389-7125-4df0-877f-9925b315913f$70a9cd5f-ec47-4c45-b822-64c3ff72322a$8a606467-0434-418f-85e5-40a35c9df95f$5905847d-2358-4380-a5a0-c5ac8c716839$f72045aa-fa31-40bf-b80c-5259583f1d30$eacafc14-d0f6-472f-be69-2ab0d81e41b1$e3be7db2-a307-4083-bb35-db4e70dfe1bf$d2d811d0-9e38-4fc6-b576-3156309b3715$6048a5ad-2964-4aab-a708-32754e52eb1c$755d9324-5447-4240-9a17-6e212dab4edd$bfbfe9cf-9a28-4b52-8c50-4ab9965a6288$63530cf1-e20d-4250-a6e0-68443253a0e7$f77783b5-b35a-4437-b436-323d7668d456$909a83f1-507c-4d8f-855e-f1a45d3aa927$de01ba69-cc44-4f3a-8dfa-98f4a194b28a$b3e11050-b799-4d88-b5cc-bc9d057be7bc$73a811a3-8c64-4bf0-9656-1d8488819f45$28f3894f-6135-4359-842e-ef5e783fc469$113fa658-4325-4ea6-a5ab-6337889006f4$897d515d-bfda-4a8f-abbb-9276d69f0f4d$2bad907d-5859-4465-8ed6-4285642d9874$5e402035-3a17-4072-8288-cbc613bc4cba$14e2c87f-557e-45fa-8036-464d5b4deac5$8d64ec48-639e-4fc2-9c6c-5cd207c1ba75$e5555433-b323-4af5-805c-db592461307b$08b24136-c292-4360-a90e-a8fd82d45d6b$0e341cb6-bbca-4581-858f-50b4e2ca858a$c66b8dec-aa58-4508-9f93-70d65ba2c051$8fe19ca9-6618-4c70-8eca-6ba002630ca9$4f785723-2f6a-4dcd-82a7-8d15daf191e8$28c7a5ed-cbc7-4865-a6a9-b6395ea80a5c$54662c5d-7ba3-4e96-88ce-3c9ba1907f8e$e500c93a-9a4a-4141-819b-051c4e5d5bb0$b6399549-c754-498a-887c-401f252ba21f$794970ef-f2d2-4dc8-ae43-2b1ecc306a74$400ad142-8fad-42f6-a8cb-3a1b9c56f5dblast_hot_reload_timeshortpathIntro to Julia.jlprocess_statusreadypath:/home/runner/work/course/course/probprog/Intro to Julia.jlpluto_versionv0.20.19last_save_timeA}*cell_orderg$660571c4-3d5e-4eba-b6d9-bcab17c2a2ee$77271b72-bafe-11f0-8fa2-33da6741b124$705dedd6-755f-4a18-9d4d-cde8c9755e05$02c03dad-d974-4584-9766-0e7ea79047e0$9d9799b0-2e0c-4180-ae80-44e5c268c8b4$f5df9bc3-79df-4e0b-b199-9ade76f53894$29f6c7eb-69ba-4072-a77d-7097235c1dac$3e1ca65e-f4cc-4d28-8139-f04d70980ecb$6b4c2d62-b1d0-4f42-9ee6-eb2d9f8ba98a$5d627a4e-5dee-4c25-b99c-ae7e4221109f$14ab0808-3fdb-4113-8854-43255987a006$e608d8a8-8faa-4302-bf7e-ae135cef47a4$0103d1f6-ea03-4497-a0de-e1b0c181d648$7bc7fb04-9d74-4970-b06b-5bc95d7be757$5013d835-99b7-4b08-bc97-8085017d47ab$f5d8574f-b115-4555-8c0e-41f95824740a$6bb76a54-2df8-4604-923a-ebb428eb0353$83e2a97e-72d7-404e-b138-f2c5d30d6365$51123db8-3fdf-4497-b121-ce5b989bc063$6969d1e5-38d0-432d-842e-153139f86613$ec16be17-cdbd-467a-be07-a6fed4e05dad$7a1e8d0a-cffc-497a-88a7-fd9757bc8eda$8ebd00be-c361-4080-b1a6-8eca643439a5$ecea873a-ab10-4539-ba66-b05b1ebdf1ec$77f5b5de-040f-4406-bb57-c1fe58e3b32b$3d89c37f-0876-4ba1-aa35-0a7273d4d269$0d8059ae-c158-43f2-81a8-9cba2f667177$ccbf4589-8d25-434e-a7f4-3d972b4ee078$895960bf-1ee2-4aa8-b38c-5857525b1ddc$96b831a8-09ba-4792-8268-14c368b804f8$519dbc40-2c83-4fda-b6fe-d3547b43b407$881a67da-5f59-437d-91ce-8c8113985fb6$58b280bc-914e-45e2-bae4-3c767ba09ec3$be6f2317-24c7-470c-bde8-233ad3d6f3bd$c97780c0-c60f-443d-98c8-100e67576e23$174612aa-d8a0-4a21-be83-91648dac1f61$4588df60-9c5b-49cc-a3a1-44db790d00ed$e47bad96-4092-4d0a-8035-f05310359565$ab9f639a-abd0-44e0-bb89-ed27472a641d$767a5b82-b007-42aa-897c-6dfa4eadf28a$cf9d6290-0aeb-484a-8816-6972fd3c4891$2e3b7a55-a85b-4498-8dc4-c14853ec06ab$cc21a0ab-d413-453b-94a0-15d33524ca4f$ff063276-46ef-4768-a0b1-878e9eb1a13e$2f5ff4dc-5267-4d64-aca5-a6a0be536f8f$122a00c1-d3d4-43da-b5d1-6bc660f5d43e$034f3378-6dc8-4fff-b8a7-afdc330b4f01$408e3447-21bb-4617-bdf2-d60f7cfb8ece$a02297a2-8660-4fd1-95af-438f363b9f29$277c5574-910b-4f05-8661-ef81278e9319$61f5260a-dd5b-4ca1-9d55-30d7fd453f4e$66a29ea6-d467-4909-964d-c88d68da4d50$826ef035-bf26-45ac-b33c-dc2dcaa23f7c$ce73c7c3-5025-4784-8657-b2b67097c702$3889c64c-d018-4c04-80a4-246aaede7d4e$a5a577b6-4266-4698-a3a1-7147590795b5$721d9bd7-c04c-4874-897e-61fde49ba257$90d21b8f-b29b-420c-894b-a94abb52f2bb$3b0e1194-e6df-46e4-8c41-032f5beeb8fa$9dc43526-5604-4251-aa22-3aff5fa3bd0b$ebbf4498-4082-44a0-a904-c80ca6dab2c7$44add801-211a-423d-9279-54ab6a101420$25c4102b-9ed9-44c7-9c5f-9d7e1810f229$a520e936-d80b-42fe-9b45-28d972383ff9$f4753dd6-51f7-48db-b8e9-26b550af1bac$dab1a565-43a9-48ac-896f-cc0ee7856552$d5a8ec92-a4fa-46e6-983c-44572a74f886$9f761389-7125-4df0-877f-9925b315913f$70a9cd5f-ec47-4c45-b822-64c3ff72322a$8a606467-0434-418f-85e5-40a35c9df95f$5905847d-2358-4380-a5a0-c5ac8c716839$f72045aa-fa31-40bf-b80c-5259583f1d30$eacafc14-d0f6-472f-be69-2ab0d81e41b1$e3be7db2-a307-4083-bb35-db4e70dfe1bf$d2d811d0-9e38-4fc6-b576-3156309b3715$6048a5ad-2964-4aab-a708-32754e52eb1c$755d9324-5447-4240-9a17-6e212dab4edd$bfbfe9cf-9a28-4b52-8c50-4ab9965a6288$63530cf1-e20d-4250-a6e0-68443253a0e7$f77783b5-b35a-4437-b436-323d7668d456$909a83f1-507c-4d8f-855e-f1a45d3aa927$de01ba69-cc44-4f3a-8dfa-98f4a194b28a$b3e11050-b799-4d88-b5cc-bc9d057be7bc$73a811a3-8c64-4bf0-9656-1d8488819f45$28f3894f-6135-4359-842e-ef5e783fc469$113fa658-4325-4ea6-a5ab-6337889006f4$897d515d-bfda-4a8f-abbb-9276d69f0f4d$2bad907d-5859-4465-8ed6-4285642d9874$5e402035-3a17-4072-8288-cbc613bc4cba$14e2c87f-557e-45fa-8036-464d5b4deac5$8d64ec48-639e-4fc2-9c6c-5cd207c1ba75$e5555433-b323-4af5-805c-db592461307b$08b24136-c292-4360-a90e-a8fd82d45d6b$0e341cb6-bbca-4581-858f-50b4e2ca858a$c66b8dec-aa58-4508-9f93-70d65ba2c051$8fe19ca9-6618-4c70-8eca-6ba002630ca9$4f785723-2f6a-4dcd-82a7-8d15daf191e8$28c7a5ed-cbc7-4865-a6a9-b6395ea80a5c$54662c5d-7ba3-4e96-88ce-3c9ba1907f8e$794970ef-f2d2-4dc8-ae43-2b1ecc306a74$e500c93a-9a4a-4141-819b-051c4e5d5bb0$b6399549-c754-498a-887c-401f252ba21f$400ad142-8fad-42f6-a8cb-3a1b9c56f5dbpublished_objectsnbpkginstall_time_ns?Binstantiatedòinstalled_versionsLinearAlgebrastdlibDistributions0.25.122BmlipTeachingTools1.3.1DataFrames1.8.1Plots1.40.20ProgressMeter1.11.0terminal_outputsnbpkg_sync Resolving... ===  Installed StableRNGs ─ v1.0.4  Project No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_ldphrmybhh/Project.toml`  Updating `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_ldphrmybhh/Manifest.toml` [f43a241f] ↑ Downloads v1.6.0 ⇒ v1.7.0 [44cfe95a] ↑ Pkg v1.12.0 ⇒ v1.12.1 [deac9b47] ↑ LibCURL_jll v8.11.1+1 ⇒ v8.15.0+0 [14a3606d] ↑ MozillaCACerts_jll v2025.5.20 ⇒ v2025.11.4 [458c3c95] ↑ OpenSSL_jll v3.5.1+0 ⇒ v3.5.4+0 [3f19e933] ↑ p7zip_jll v17.5.0+2 ⇒ v17.7.0+0 Instantiating... === Precompiling... === LinearAlgebra Resolving... ===  Installed StableRNGs ─ v1.0.4  Project No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_ldphrmybhh/Project.toml`  Updating `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_ldphrmybhh/Manifest.toml` [f43a241f] ↑ Downloads v1.6.0 ⇒ v1.7.0 [44cfe95a] ↑ Pkg v1.12.0 ⇒ v1.12.1 [deac9b47] ↑ LibCURL_jll v8.11.1+1 ⇒ v8.15.0+0 [14a3606d] ↑ MozillaCACerts_jll v2025.5.20 ⇒ v2025.11.4 [458c3c95] ↑ OpenSSL_jll v3.5.1+0 ⇒ v3.5.4+0 [3f19e933] ↑ p7zip_jll v17.5.0+2 ⇒ v17.7.0+0 Instantiating... === Precompiling... === Distributions Resolving... ===  Installed StableRNGs ─ v1.0.4  Project No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_ldphrmybhh/Project.toml`  Updating `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_ldphrmybhh/Manifest.toml` [f43a241f] ↑ Downloads v1.6.0 ⇒ v1.7.0 [44cfe95a] ↑ Pkg v1.12.0 ⇒ v1.12.1 [deac9b47] ↑ LibCURL_jll v8.11.1+1 ⇒ v8.15.0+0 [14a3606d] ↑ MozillaCACerts_jll v2025.5.20 ⇒ v2025.11.4 [458c3c95] ↑ OpenSSL_jll v3.5.1+0 ⇒ v3.5.4+0 [3f19e933] ↑ p7zip_jll v17.5.0+2 ⇒ v17.7.0+0 Instantiating... === Precompiling... === Plots Resolving... ===  Installed StableRNGs ─ v1.0.4  Project No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_ldphrmybhh/Project.toml`  Updating `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_ldphrmybhh/Manifest.toml` [f43a241f] ↑ Downloads v1.6.0 ⇒ v1.7.0 [44cfe95a] ↑ Pkg v1.12.0 ⇒ v1.12.1 [deac9b47] ↑ LibCURL_jll v8.11.1+1 ⇒ v8.15.0+0 [14a3606d] ↑ MozillaCACerts_jll v2025.5.20 ⇒ v2025.11.4 [458c3c95] ↑ OpenSSL_jll v3.5.1+0 ⇒ v3.5.4+0 [3f19e933] ↑ p7zip_jll v17.5.0+2 ⇒ v17.7.0+0 Instantiating... === Precompiling... === BmlipTeachingTools Resolving... ===  Installed StableRNGs ─ v1.0.4  Project No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_ldphrmybhh/Project.toml`  Updating `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_ldphrmybhh/Manifest.toml` [f43a241f] ↑ Downloads v1.6.0 ⇒ v1.7.0 [44cfe95a] ↑ Pkg v1.12.0 ⇒ v1.12.1 [deac9b47] ↑ LibCURL_jll v8.11.1+1 ⇒ v8.15.0+0 [14a3606d] ↑ MozillaCACerts_jll v2025.5.20 ⇒ v2025.11.4 [458c3c95] ↑ OpenSSL_jll v3.5.1+0 ⇒ v3.5.4+0 [3f19e933] ↑ p7zip_jll v17.5.0+2 ⇒ v17.7.0+0 Instantiating... === Precompiling... === DataFrames Resolving... ===  Installed StableRNGs ─ v1.0.4  Project No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_ldphrmybhh/Project.toml`  Updating `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_ldphrmybhh/Manifest.toml` [f43a241f] ↑ Downloads v1.6.0 ⇒ v1.7.0 [44cfe95a] ↑ Pkg v1.12.0 ⇒ v1.12.1 [deac9b47] ↑ LibCURL_jll v8.11.1+1 ⇒ v8.15.0+0 [14a3606d] ↑ MozillaCACerts_jll v2025.5.20 ⇒ v2025.11.4 [458c3c95] ↑ OpenSSL_jll v3.5.1+0 ⇒ v3.5.4+0 [3f19e933] ↑ p7zip_jll v17.5.0+2 ⇒ v17.7.0+0 Instantiating... === Precompiling... === ProgressMeter Resolving... ===  Installed StableRNGs ─ v1.0.4  Project No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_ldphrmybhh/Project.toml`  Updating `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_ldphrmybhh/Manifest.toml` [f43a241f] ↑ Downloads v1.6.0 ⇒ v1.7.0 [44cfe95a] ↑ Pkg v1.12.0 ⇒ v1.12.1 [deac9b47] ↑ LibCURL_jll v8.11.1+1 ⇒ v8.15.0+0 [14a3606d] ↑ MozillaCACerts_jll v2025.5.20 ⇒ v2025.11.4 [458c3c95] ↑ OpenSSL_jll v3.5.1+0 ⇒ v3.5.4+0 [3f19e933] ↑ p7zip_jll v17.5.0+2 ⇒ v17.7.0+0 Instantiating... === Precompiling... === enabled÷restart_recommended_msgrestart_required_msgbusy_packageswaiting_for_permission,waiting_for_permission_but_probably_disabled«cell_inputsg$122a00c1-d3d4-43da-b5d1-6bc660f5d43ecell_id$122a00c1-d3d4-43da-b5d1-6bc660f5d43ecodemmd""" If you need both the index and the value of the array element, you can use the `enumerate` command: """metadatashow_logsèdisabled®skip_as_script«code_folded$f72045aa-fa31-40bf-b80c-5259583f1d30cell_id$f72045aa-fa31-40bf-b80c-5259583f1d30code\md""" You will see much more of the `Distributions.jl` package in this course. See also: """metadatashow_logsèdisabled®skip_as_script«code_folded$ccbf4589-8d25-434e-a7f4-3d972b4ee078cell_id$ccbf4589-8d25-434e-a7f4-3d972b4ee078codew = [1 2 3 4]metadatashow_logsèdisabled®skip_as_script«code_folded$3889c64c-d018-4c04-80a4-246aaede7d4ecell_id$3889c64c-d018-4c04-80a4-246aaede7d4ecode٫begin function foo(bar::Float64) message = "Boo!" return message end function foo(bar::Integer) message = "Bah!" return message end foo(1) endmetadatashow_logsèdisabled®skip_as_script«code_folded$dab1a565-43a9-48ac-896f-cc0ee7856552cell_id$dab1a565-43a9-48ac-896f-cc0ee7856552codemd""" ## Packages The base form of Julia has many wonderful functions and methods. But not everything. To extend functionality, we have to import additional software packages. Below is a list of the few packages we cover in today's tutorial. But you'll see more later in the course. """metadatashow_logsèdisabled®skip_as_script«code_folded$28f3894f-6135-4359-842e-ef5e783fc469cell_id$28f3894f-6135-4359-842e-ef5e783fc469codemd""" ## Errors & Debugging - References: [Stack traces](https://docs.julialang.org/en/v1/manual/stacktraces/) When you call a function that Julia doesn't know, it will return a list of the steps it took to execute your command and point to where its progress was blocked. This is highly useful but it typically requires a bit of practice to parse (i.e., read and filter) stack traces. ### MethodError Suppose we write a function that expects an `Integer` input and call that function with an `Float64` argument: """metadatashow_logsèdisabled®skip_as_script«code_folded$f77783b5-b35a-4437-b436-323d7668d456cell_id$f77783b5-b35a-4437-b436-323d7668d456codecmd""" It is possible to add plots to the same figure by using a `!` added to your plot command. """metadatashow_logsèdisabled®skip_as_script«code_folded$8d64ec48-639e-4fc2-9c6c-5cd207c1ba75cell_id$8d64ec48-639e-4fc2-9c6c-5cd207c1ba75codeadd1(3)metadatashow_logsèdisabled®skip_as_script«code_folded$6bb76a54-2df8-4604-923a-ebb428eb0353cell_id$6bb76a54-2df8-4604-923a-ebb428eb0353code٠md""" They can be concatenated by multiplication (which is an example of a function, namely `*`, which acts differently on different input argument types): """metadatashow_logsèdisabled®skip_as_script«code_folded$25c4102b-9ed9-44c7-9c5f-9d7e1810f229cell_id$25c4102b-9ed9-44c7-9c5f-9d7e1810f229code%begin e = [1, 3, 2] [sort(e) e] endmetadatashow_logsèdisabled®skip_as_script«code_folded$28c7a5ed-cbc7-4865-a6a9-b6395ea80a5ccell_id$28c7a5ed-cbc7-4865-a6a9-b6395ea80a5ccode[md""" ### Stack trace The stack trace will show you exactly _where_ an error happened. """metadatashow_logsèdisabled®skip_as_script«code_folded$ec16be17-cdbd-467a-be07-a6fed4e05dadcell_id$ec16be17-cdbd-467a-be07-a6fed4e05dadcodemd""" Julia also has a `Symbol` type, which is used for [meta-programming](https://docs.julialang.org/en/v1/manual/metaprogramming/) (not important for this course). A `Symbol` type is characterized by a `:` in front of a word. For example: """metadatashow_logsèdisabled®skip_as_script«code_folded$77271b72-bafe-11f0-8fa2-33da6741b124cell_id$77271b72-bafe-11f0-8fa2-33da6741b124codemd""" This notebook will teach you some of the basic programming routines in Julia. You will need these skills to complete the probabilistic programming assignments later on in the course. We will assume basic familiarity with programming, such as for-loops, if-else statements and function definitions. Resources: - **Julia Basics** from _"Julia Programming for Machine Learning"_ taught at TU Berlin: - [L1: Essentials](https://adrianhill.de/julia-ml-course/L1_Basics_1/) (syntax, types, operations, functions) - [L2: Arrays](https://adrianhill.de/julia-ml-course/L2_Basics_2/) (vector, matrix, linear algebra) - [JuliaLang documentation](https://docs.julialang.org/en/v1/) - [Differences to Python, Matlab, C and Java](https://docs.julialang.org/en/v1/manual/noteworthy-differences/) - [Video on getting started](https://www.youtube.com/watch?v=4igzy3bGVkQ&list=PLP8iPy9hna6SCcFv3FvY_qjAmtTsNYHQE) - [Pluto.jl documentation](https://plutojl.org/en/docs/) """metadatashow_logsèdisabled®skip_as_script«code_folded$73a811a3-8c64-4bf0-9656-1d8488819f45cell_id$73a811a3-8c64-4bf0-9656-1d8488819f45code٥md""" Macros are a somewhat advanced form of metaprogramming. You will not need to define any new macros; this instruction is just here to explain what they are. """metadatashow_logsèdisabled®skip_as_script«code_folded$70a9cd5f-ec47-4c45-b822-64c3ff72322acell_id$70a9cd5f-ec47-4c45-b822-64c3ff72322acodeeigen([3. 2.;2. 0.4])metadatashow_logsèdisabled®skip_as_script«code_folded$63530cf1-e20d-4250-a6e0-68443253a0e7cell_id$63530cf1-e20d-4250-a6e0-68443253a0e7codecscatter(X[:,1], X[:,2], xlabel="X_1", ylabel="X_2", markersize=10, markershape=:circle)metadatashow_logsèdisabled®skip_as_script«code_folded$400ad142-8fad-42f6-a8cb-3a1b9c56f5dbcell_id$400ad142-8fad-42f6-a8cb-3a1b9c56f5dbcodemd""" ## Closing That's it for now. If you encounter mysterious errors, please let us know on [Piazza](https://piazza.com/tue.nl/winter2026/5ssd0). We can add them to this primer. And if you have any feedback about improving this short primer on programming in Julia, let us know! """metadatashow_logsèdisabled®skip_as_script«code_folded$4588df60-9c5b-49cc-a3a1-44db790d00edcell_id$4588df60-9c5b-49cc-a3a1-44db790d00edcode0md""" ## Pluto notebooks The course is built in Pluto.jl, a reactive programming environment. Pluto notebooks are wonderfully intuitive and interactive, and are already revolutionizing mathematics and computer science education (e.g., [18.S191 Computational Thinking @MIT](https://computationalthinking.mit.edu)). A few things to be aware of when working in Pluto notebooks: - Code is not executed sequentially. In other words, you can call a variable in a cell even if that variable is defined in a later cell. - You cannot re-use variable names, i.e., you cannot overwrite a variable with a different variable in a latter cell. - A cell can only execute a single function/instruction; if you want to execute more instructions, you have to wrap them in a `begin .. end` environment. - Each Pluto notebook manages its own software packages (more on that later). - The `Live docs` button on the bottom-right corner can be used to look up documentation of functions. - The `Status` button on the bottom-right corner displays what the kernel is doing in the background. """metadatashow_logsèdisabled®skip_as_script«code_folded$a5a577b6-4266-4698-a3a1-7147590795b5cell_id$a5a577b6-4266-4698-a3a1-7147590795b5code md""" Note that the `return` argument does not need to be at the end of a function ([the return keyword](https://docs.julialang.org/en/v1/manual/functions/#The-return-Keyword)). You don't actually need the `function` keyword if you have simple enough functions: """metadatashow_logsèdisabled®skip_as_script«code_folded$ecea873a-ab10-4539-ba66-b05b1ebdf1eccell_id$ecea873a-ab10-4539-ba66-b05b1ebdf1eccodemd""" You will not have to use `Symbol`s in the course, but you may see one every once in a while in the lecture notes. For example, the `plot` command (see Visualization section), may have a `markershape=:cross` argument. """metadatashow_logsèdisabled®skip_as_script«code_folded$cf9d6290-0aeb-484a-8816-6972fd3c4891cell_id$cf9d6290-0aeb-484a-8816-6972fd3c4891codesin.([1., 2., 3.])metadatashow_logsèdisabled®skip_as_script«code_folded$e500c93a-9a4a-4141-819b-051c4e5d5bb0cell_id$e500c93a-9a4a-4141-819b-051c4e5d5bb0code5md""" Here is the function used in the last cell: """metadatashow_logsèdisabled®skip_as_script«code_folded$755d9324-5447-4240-9a17-6e212dab4eddcell_id$755d9324-5447-4240-9a17-6e212dab4eddcodeCmd""" `plot` and `scatter` are the most useful commands. A `scatter` command will ignore properties such as `linewidth` and `linestyle` (since there are no lines) and will listen to `markersize` and `markershape` commands (see [Supported Attributes](https://docs.juliaplots.org/stable/generated/supported/) in the API). """metadatashow_logsèdisabled®skip_as_script«code_folded$3d89c37f-0876-4ba1-aa35-0a7273d4d269cell_id$3d89c37f-0876-4ba1-aa35-0a7273d4d269codev = [1,2,3,4]metadatashow_logsèdisabled®skip_as_script«code_folded$794970ef-f2d2-4dc8-ae43-2b1ecc306a74cell_id$794970ef-f2d2-4dc8-ae43-2b1ecc306a74codegive_magic_number(7)metadatashow_logsèdisabled®skip_as_script«code_folded$5905847d-2358-4380-a5a0-c5ac8c716839cell_id$5905847d-2358-4380-a5a0-c5ac8c716839code.begin px = Normal(1.0, 0.5) pdf(px, 0.0) endmetadatashow_logsèdisabled®skip_as_script«code_folded$277c5574-910b-4f05-8661-ef81278e9319cell_id$277c5574-910b-4f05-8661-ef81278e9319codeVmd""" ## Control flow - References: [Control flow](https://docs.julialang.org/en/v1/manual/control-flow/), [Logical Operators](https://docs.julialang.org/en/v1/manual/missing/#Logical-operators) Control flow refers to redirecting how a compiler goes through a program. Instead of traversing it line-by-line, things like `if-else` statements can make a compiler skip steps. These require logical operations: you can use `==` to check if two variables have the same value, `===` to check if they are actually the same object (i.e., same memory reference) and `!=` to check if they're not equal. """metadatashow_logsèdisabled®skip_as_script«code_folded$ce73c7c3-5025-4784-8657-b2b67097c702cell_id$ce73c7c3-5025-4784-8657-b2b67097c702codeCmd""" ## Functions - References: [Functions](https://docs.julialang.org/en/v1/manual/functions/), [Mutation](https://docs.julialang.org/en/v1/manual/style-guide/#bang-convention) Function and expressions are a core component of the julia language. Its "multiple dispatch" feature means that you can define multiple functions with the same name but with behaviour that depends on the input argument types. When you're starting out, you may not notice this so much, but you will start to appreciate this feature tremendously when you begin to professionally develop software. """metadatashow_logsèdisabled®skip_as_script«code_folded$f5d8574f-b115-4555-8c0e-41f95824740acell_id$f5d8574f-b115-4555-8c0e-41f95824740acodetypeof(d)metadatashow_logsèdisabled®skip_as_script«code_folded$d5a8ec92-a4fa-46e6-983c-44572a74f886cell_id$d5a8ec92-a4fa-46e6-983c-44572a74f886codeفbegin using BmlipTeachingTools using LinearAlgebra using DataFrames using ProgressMeter using Distributions using Plots endmetadatashow_logsèdisabled®skip_as_script«code_folded$9dc43526-5604-4251-aa22-3aff5fa3bd0bcell_id$9dc43526-5604-4251-aa22-3aff5fa3bd0bcode#fn(; number::Number = 1) = 1/numbermetadatashow_logsèdisabled®skip_as_script«code_folded$705dedd6-755f-4a18-9d4d-cde8c9755e05cell_id$705dedd6-755f-4a18-9d4d-cde8c9755e05codeTableOfContents()metadatashow_logsèdisabled®skip_as_script«code_folded$034f3378-6dc8-4fff-b8a7-afdc330b4f01cell_id$034f3378-6dc8-4fff-b8a7-afdc330b4f01code:for (j,n) in enumerate(range(0,3)) @info("$j, $n") endmetadatashow_logsèdisabled®skip_as_script«code_folded$61f5260a-dd5b-4ca1-9d55-30d7fd453f4ecell_id$61f5260a-dd5b-4ca1-9d55-30d7fd453f4ecodeebegin r = 3.0 if r < 0 "Negative" elseif r == 0 "0.0" else "Positive" end endmetadatashow_logsèdisabled®skip_as_script«code_folded$83e2a97e-72d7-404e-b138-f2c5d30d6365cell_id$83e2a97e-72d7-404e-b138-f2c5d30d6365codeab = "a"*"b"metadatashow_logsèdisabled®skip_as_script«code_folded$cc21a0ab-d413-453b-94a0-15d33524ca4fcell_id$cc21a0ab-d413-453b-94a0-15d33524ca4fcodefor n = 1:2:5 @info(n) endmetadatashow_logsèdisabled®skip_as_script«code_folded$8fe19ca9-6618-4c70-8eca-6ba002630ca9cell_id$8fe19ca9-6618-4c70-8eca-6ba002630ca9codeadd(3,4)metadatashow_logsèdisabled®skip_as_script«code_folded$408e3447-21bb-4617-bdf2-d60f7cfb8ececell_id$408e3447-21bb-4617-bdf2-d60f7cfb8ececodeumd""" You may be familiar with "list comprehension", which is a shortened form of iterating through a collection: """metadatashow_logsèdisabled®skip_as_script«code_folded$e608d8a8-8faa-4302-bf7e-ae135cef47a4cell_id$e608d8a8-8faa-4302-bf7e-ae135cef47a4codetypeof(c)metadatashow_logsèdisabled®skip_as_script«code_folded$e47bad96-4092-4d0a-8035-f05310359565cell_id$e47bad96-4092-4d0a-8035-f05310359565codemd""" ## Broadcasting - Reference: [Broadcasting](https://docs.julialang.org/en/v1/manual/arrays/#Broadcasting) You can apply functions to elements in an array by placing a dot in front: """metadatashow_logsèdisabled®skip_as_script«code_folded$f5df9bc3-79df-4e0b-b199-9ade76f53894cell_id$f5df9bc3-79df-4e0b-b199-9ade76f53894codetypeof(a)metadatashow_logsèdisabled®skip_as_script«code_folded$be6f2317-24c7-470c-bde8-233ad3d6f3bdcell_id$be6f2317-24c7-470c-bde8-233ad3d6f3bdcodeHbegin A = [3 2 1; 2 3 2; 1 2 3] x = [0, 1, 2] A*x endmetadatashow_logsèdisabled®skip_as_script«code_folded$767a5b82-b007-42aa-897c-6dfa4eadf28acell_id$767a5b82-b007-42aa-897c-6dfa4eadf28acode.md""" This also works for named functions: """metadatashow_logsèdisabled®skip_as_script«code_folded$58b280bc-914e-45e2-bae4-3c767ba09ec3cell_id$58b280bc-914e-45e2-bae4-3c767ba09ec3codeSmd""" Matrix operations are intuitive and similar to the mathematical notation: """metadatashow_logsèdisabled®skip_as_script«code_folded$a02297a2-8660-4fd1-95af-438f363b9f29cell_id$a02297a2-8660-4fd1-95af-438f363b9f29code["n = $n" for n in range(2,4)]metadatashow_logsèdisabled®skip_as_script«code_folded$02c03dad-d974-4584-9766-0e7ea79047e0cell_id$02c03dad-d974-4584-9766-0e7ea79047e0codemd""" ## Data types - References: [Numbers](https://docs.julialang.org/en/v1/manual/integers-and-floating-point-numbers/), [Integers and Float](https://docs.julialang.org/en/v1/manual/integers-and-floating-point-numbers/), [Strings](https://docs.julialang.org/en/v1/base/strings/), [Symbols](https://docs.julialang.org/en/v1/manual/metaprogramming/). Numbers in Julia have specific types, most notably `Integer`, `Real` and `Complex`. (See [this documentation page](https://docs.julialang.org/en/v1/base/numbers/) for the full type tree.) It is important to be aware of what type your numbers are because many functions operate differently on different number types. """metadatashow_logsèdisabled®skip_as_script«code_folded$721d9bd7-c04c-4874-897e-61fde49ba257cell_id$721d9bd7-c04c-4874-897e-61fde49ba257codefn(x::Number) = 1/xmetadatashow_logsèdisabled®skip_as_script«code_folded$14e2c87f-557e-45fa-8036-464d5b4deac5cell_id$14e2c87f-557e-45fa-8036-464d5b4deac5codeumd""" You should read this as "there exists a function called `add1` that expects an `Integer` input." Try that. """metadatashow_logsèdisabled®skip_as_script«code_folded$3e1ca65e-f4cc-4d28-8139-f04d70980ecbcell_id$3e1ca65e-f4cc-4d28-8139-f04d70980ecbcodeb = 3.0metadatashow_logsèdisabled®skip_as_script«code_folded$e5555433-b323-4af5-805c-db592461307bcell_id$e5555433-b323-4af5-805c-db592461307bcode/md""" #### Mathced types in MethodError The red highlighting of $(html"::Integer") is also important but requires a slightly more complicated example. Suppose we have a function with two `Integer` inputs and we call with `Float64` and `Int64` arguments. """metadatashow_logsèdisabled®skip_as_script«code_folded$881a67da-5f59-437d-91ce-8c8113985fb6cell_id$881a67da-5f59-437d-91ce-8c8113985fb6code9begin U = zeros(2,3) V = ones(2,3) W = randn(2,3) end;metadatashow_logsèdisabled®skip_as_script«code_folded$b6399549-c754-498a-887c-401f252ba21fcell_id$b6399549-c754-498a-887c-401f252ba21fcodeTfunction give_magic_number(x::Real) kk = x*2 ll = 3*kk mm = kl*ll nn = mm*ll endmetadatashow_logsèdisabled®skip_as_script«code_folded$90d21b8f-b29b-420c-894b-a94abb52f2bbcell_id$90d21b8f-b29b-420c-894b-a94abb52f2bbcodefn(4)metadatashow_logsèdisabled®skip_as_script«code_folded$9d9799b0-2e0c-4180-ae80-44e5c268c8b4cell_id$9d9799b0-2e0c-4180-ae80-44e5c268c8b4codea = 3metadatashow_logsèdisabled®skip_as_script«code_folded$9f761389-7125-4df0-877f-9925b315913fcell_id$9f761389-7125-4df0-877f-9925b315913fcode^md""" Below are some examples of importing packages and using their added functionalities. """metadatashow_logsèdisabled®skip_as_script«code_folded$897d515d-bfda-4a8f-abbb-9276d69f0f4dcell_id$897d515d-bfda-4a8f-abbb-9276d69f0f4dcodeadd1(3.1415)metadatashow_logsèdisabled®skip_as_script«code_folded$ebbf4498-4082-44a0-a904-c80ca6dab2c7cell_id$ebbf4498-4082-44a0-a904-c80ca6dab2c7code[fn() fn(number=3)]metadatashow_logsèdisabled®skip_as_script«code_folded$2bad907d-5859-4465-8ed6-4285642d9874cell_id$2bad907d-5859-4465-8ed6-4285642d9874codeHmd""" Note that we first of all get a `MethodError`. This points to the fact that Julia could not find the function (i.e, method) that you asked for; `add1(::Float64)` does not exist. Furthermore, Julia provides a list of "Closest candidates" which are functions of the same name with different input arguments. It reports: """metadatashow_logsèdisabled®skip_as_script«code_folded$660571c4-3d5e-4eba-b6d9-bcab17c2a2eecell_id$660571c4-3d5e-4eba-b6d9-bcab17c2a2eecodetitle("Programming in Julia")metadatashow_logsèdisabled®skip_as_script«code_folded$4f785723-2f6a-4dcd-82a7-8d15daf191e8cell_id$4f785723-2f6a-4dcd-82a7-8d15daf191e8codemd""" ### What to do with errors? To summarize, when you get an error, it is important to **take your time**, and **read the message**. If you want to know _where_ something happened, look at the stack trace. Try to see an error message as **positive feedback**: you are on the right track, and Julia is trying to help you to write the correct code. The type of error can also be informative. The `MethodError` is probably the error you will see most often. """metadatashow_logsèdisabled®skip_as_script«code_folded$51123db8-3fdf-4497-b121-ce5b989bc063cell_id$51123db8-3fdf-4497-b121-ce5b989bc063codeFmd""" You can incorporate numbers into strings through a `$` call: """metadatashow_logsèdisabled®skip_as_script«code_folded$c66b8dec-aa58-4508-9f93-70d65ba2c051cell_id$c66b8dec-aa58-4508-9f93-70d65ba2c051codexmd""" We again get the `MethodError` that the function we asked for doesn't exist and a suggested alternative (i.e., "closest candidate"). But this time, only the first argument $(html"::Integer") is highlighted in red. Julia checks your input argument types against those in the closest candidates. This tells you _what_ to change: the solution would be to either: - Change the call: Make the first argument of your function call to an `Integer` type. That would be `add(3, 4)`. - Change the defintion: Make the function accept a more general `Real` number as the first argument. """metadatashow_logsèdisabled®skip_as_script«code_folded$895960bf-1ee2-4aa8-b38c-5857525b1ddccell_id$895960bf-1ee2-4aa8-b38c-5857525b1ddccode`md""" Matrices can be constructed by separating elements with spaces and rows by semicolons: """metadatashow_logsèdisabled®skip_as_script«code_folded$08b24136-c292-4360-a90e-a8fd82d45d6bcell_id$08b24136-c292-4360-a90e-a8fd82d45d6bcode9function add(a::Integer, b::Integer) return a + b endmetadatashow_logsèdisabled®skip_as_script«code_folded$e3be7db2-a307-4083-bb35-db4e70dfe1bfcell_id$e3be7db2-a307-4083-bb35-db4e70dfe1bfcodemd""" ## Visualization - Reference: [Plots.jl](https://github.com/JuliaPlots/Plots.jl) Plots.jl provides a common interface to call various other visualization backends (GR, Matplotlib, PGFPlotsX, Plotly, etc.). In other words, commands like `plot(..)` will be translated into the appropriate command for the backend. So, it does not re-invent the wheel but rather gives you access to the already enormous field of visualization tools. Below are a few examples of the most common visualization commands you'll see throughout the course. The core principle is to use a `plot` type as base command and then provide keyword arguments (in `String`, `Number` or `Symbol` type) to apply variations. """metadatashow_logsèdisabled®skip_as_script«code_folded$3b0e1194-e6df-46e4-8c41-032f5beeb8facell_id$3b0e1194-e6df-46e4-8c41-032f5beeb8facodeemd""" You can add keyword arguments to a function, which are input arguments with default values: """metadatashow_logsèdisabled®skip_as_script«code_folded$7bc7fb04-9d74-4970-b06b-5bc95d7be757cell_id$7bc7fb04-9d74-4970-b06b-5bc95d7be757codeQmd""" Strings are constructed by enclosing symbols within double parentheses. """metadatashow_logsèdisabled®skip_as_script«code_folded$6b4c2d62-b1d0-4f42-9ee6-eb2d9f8ba98acell_id$6b4c2d62-b1d0-4f42-9ee6-eb2d9f8ba98acodetypeof(b)metadatashow_logsèdisabled®skip_as_script«code_folded$826ef035-bf26-45ac-b33c-dc2dcaa23f7ccell_id$826ef035-bf26-45ac-b33c-dc2dcaa23f7ccode#r > 0 ? "Positive" : "Not positive"metadatashow_logsèdisabled®skip_as_script«code_folded$909a83f1-507c-4d8f-855e-f1a45d3aa927cell_id$909a83f1-507c-4d8f-855e-f1a45d3aa927code'begin plot(xx, pdf.(Normal(0.,1.), xx), xlabel="x", ylabel="p(x)", label="N(0,1)", color="red", linewidth=5, linestyle=:dash) plot!(xx, pdf.(Normal(1.,0.5), xx), xlabel="x", ylabel="p(x)", label="N(1,0.5)", color="blue", linestyle=:solid) endmetadatashow_logsèdisabled®skip_as_script«code_folded$de01ba69-cc44-4f3a-8dfa-98f4a194b28acell_id$de01ba69-cc44-4f3a-8dfa-98f4a194b28acode9md""" ## Macros - References: [Macros](https://docs.julialang.org/en/v1/manual/metaprogramming/#man-macros) Words that start with the `@` symbol are _macros_ in Julia, for example `@time, @test, @model`. They represent a series of functions called on an input structure and are really handy when you have to use the same set of instructions often. For example, you could define a `ProgressMeter` bar, update it at every iteration of a for-loop and write a custom print statement every time. _Or_, you could call the `@showprogress` macro on the for-loop itself: """metadatashow_logsèdisabled®skip_as_script«code_folded$6969d1e5-38d0-432d-842e-153139f86613cell_id$6969d1e5-38d0-432d-842e-153139f86613code"e = $a"metadatashow_logsèdisabled®skip_as_script«code_folded$5013d835-99b7-4b08-bc97-8085017d47abcell_id$5013d835-99b7-4b08-bc97-8085017d47abcoded = "3"metadatashow_logsèdisabled®skip_as_script«code_folded$ab9f639a-abd0-44e0-bb89-ed27472a641dcell_id$ab9f639a-abd0-44e0-bb89-ed27472a641dcode 3 .*[1 2 3]metadatashow_logsèdisabled®skip_as_script«code_folded$2f5ff4dc-5267-4d64-aca5-a6a0be536f8fcell_id$2f5ff4dc-5267-4d64-aca5-a6a0be536f8fcode4for n in range(0, stop=4, length=2) @info(n) endmetadatashow_logsèdisabled®skip_as_script«code_folded$8ebd00be-c361-4080-b1a6-8eca643439a5cell_id$8ebd00be-c361-4080-b1a6-8eca643439a5codetypeof(f)metadatashow_logsèdisabled®skip_as_script«code_folded$174612aa-d8a0-4a21-be83-91648dac1f61cell_id$174612aa-d8a0-4a21-be83-91648dac1f61codex'*A*xmetadatashow_logsèdisabled®skip_as_script«code_folded$113fa658-4325-4ea6-a5ab-6337889006f4cell_id$113fa658-4325-4ea6-a5ab-6337889006f4code.function add1(a::Integer) return a + 1 endmetadatashow_logsèdisabled®skip_as_script«code_folded$a520e936-d80b-42fe-9b45-28d972383ff9cell_id$a520e936-d80b-42fe-9b45-28d972383ff9code}md""" But if I call the `sort!` function and the original vector, you'll see that the original vector is now also sorted. """metadatashow_logsèdisabled®skip_as_script«code_folded$0103d1f6-ea03-4497-a0de-e1b0c181d648cell_id$0103d1f6-ea03-4497-a0de-e1b0c181d648codemetadatashow_logsèdisabled®skip_as_script«code_folded$5e402035-3a17-4072-8288-cbc613bc4cbacell_id$5e402035-3a17-4072-8288-cbc613bc4cbacoden@htl """
Closest candidates are:
  add1(::Integer)
"""metadatashow_logsèdisabled®skip_as_script«code_folded$6048a5ad-2964-4aab-a708-32754e52eb1ccell_id$6048a5ad-2964-4aab-a708-32754e52eb1ccode{plot(xx, pdf.(px, xx), xlabel="x", ylabel="p(x)", label="pdf", color="red", linewidth=5, linestyle=:dash)metadatashow_logsèdisabled®skip_as_script«code_folded$d2d811d0-9e38-4fc6-b576-3156309b3715cell_id$d2d811d0-9e38-4fc6-b576-3156309b3715code"xx = range(-3, stop=3, length=301)metadatashow_logsèdisabled®skip_as_script«code_folded$66a29ea6-d467-4909-964d-c88d68da4d50cell_id$66a29ea6-d467-4909-964d-c88d68da4d50code3md""" Simple `if-else` statements can often be replaced by `ternary` checks. Essentially, you ask a question (a logical operation followed by `?`) and then tell the program what to do when the answer is yes (written immediately after the question) or no (written after the yes-answer followed by a `:`). """metadatashow_logsèdisabled®skip_as_script«code_folded$44add801-211a-423d-9279-54ab6a101420cell_id$44add801-211a-423d-9279-54ab6a101420code,md""" Functions that modify their input arguments instead of creating new output variables are typically marked with an `!`. Below I have defined an unsorted vector and I call `sort` to sort it in increasing order. If I call the sort function and the original vector, then they will be different: """metadatashow_logsèdisabled®skip_as_script«code_folded$bfbfe9cf-9a28-4b52-8c50-4ab9965a6288cell_id$bfbfe9cf-9a28-4b52-8c50-4ab9965a6288codeX = randn(10,2)metadatashow_logsèdisabled®skip_as_script«code_folded$29f6c7eb-69ba-4072-a77d-7097235c1daccell_id$29f6c7eb-69ba-4072-a77d-7097235c1daccodeٹmd""" `Int64` is a 64-byte integer. Other options are 32-,16-, or 8-bit integers and they can be unsigned as well. The default real-valued numbers is a 64-bit floating-point number: """metadatashow_logsèdisabled®skip_as_script«code_folded$5d627a4e-5dee-4c25-b99c-ae7e4221109fcell_id$5d627a4e-5dee-4c25-b99c-ae7e4221109fcode*md""" Converting number types is easy: """metadatashow_logsèdisabled®skip_as_script«code_folded$77f5b5de-040f-4406-bb57-c1fe58e3b32bcell_id$77f5b5de-040f-4406-bb57-c1fe58e3b32bcode7md""" ## Array manipulation - References: [Arrays](https://docs.julialang.org/en/v1/base/arrays/) Arrays are indexed with square brackets, `A[i,j]`. You can construct a matrix by enclosing a set of numbers with square brackets. If you separate your numbers with comma's, then you will get a column vector: """metadatashow_logsèdisabled®skip_as_script«code_folded$0e341cb6-bbca-4581-858f-50b4e2ca858acell_id$0e341cb6-bbca-4581-858f-50b4e2ca858acodeadd(3.0, 4)metadatashow_logsèdisabled®skip_as_script«code_folded$54662c5d-7ba3-4e96-88ce-3c9ba1907f8ecell_id$54662c5d-7ba3-4e96-88ce-3c9ba1907f8ecodemd""" For example, the cell below contains a mistake and evaluating it will throw an error. But which line has the mistake? Press the **Show stack trace...** button or **Show more...** to see the stack trace of the error below. Where did the error happen? """metadatashow_logsèdisabled®skip_as_script«code_folded$7a1e8d0a-cffc-497a-88a7-fd9757bc8edacell_id$7a1e8d0a-cffc-497a-88a7-fd9757bc8edacodef = :foometadatashow_logsèdisabled®skip_as_script«code_folded$b3e11050-b799-4d88-b5cc-bc9d057be7bccell_id$b3e11050-b799-4d88-b5cc-bc9d057be7bccode.@showprogress for n in 1:10 sleep(0.2) endmetadatashow_logsèdisabled®skip_as_script«code_folded$519dbc40-2c83-4fda-b6fe-d3547b43b407cell_id$519dbc40-2c83-4fda-b6fe-d3547b43b407code(md""" Common array constructors are: """metadatashow_logsèdisabled®skip_as_script«code_folded$f4753dd6-51f7-48db-b8e9-26b550af1baccell_id$f4753dd6-51f7-48db-b8e9-26b550af1baccode[sort!(x) x]metadatashow_logsèdisabled®skip_as_script«code_folded$0d8059ae-c158-43f2-81a8-9cba2f667177cell_id$0d8059ae-c158-43f2-81a8-9cba2f667177codehmd""" If you use spaces, then you will construct a row vector (i.e., a matrix of dimensions 1 by n): """metadatashow_logsèdisabled®skip_as_script«code_folded$c97780c0-c60f-443d-98c8-100e67576e23cell_id$c97780c0-c60f-443d-98c8-100e67576e23codemd""" A matrix can be transposed by a single parenthesis, `A'`. Note that this does not mutate the array in memory. It just tells functions defined for matrices that it should change how it indexes the matrix's elements. """metadatashow_logsèdisabled®skip_as_script«code_folded$8a606467-0434-418f-85e5-40a35c9df95fcell_id$8a606467-0434-418f-85e5-40a35c9df95fcodeXbegin D = Dict( "a" => 1, "b" => 2, "c" => 3 ) df = DataFrame(D) endmetadatashow_logsèdisabled®skip_as_script«code_folded$ff063276-46ef-4768-a0b1-878e9eb1a13ecell_id$ff063276-46ef-4768-a0b1-878e9eb1a13ecodeّmd""" Next, we can use the `range` command to construct an array of numbers and then use the `in` command to loop over elements in the array: """metadatashow_logsèdisabled®skip_as_script«code_folded$96b831a8-09ba-4792-8268-14c368b804f8cell_id$96b831a8-09ba-4792-8268-14c368b804f8codeM = [1 2; 3 4]metadatashow_logsèdisabled®skip_as_script«code_folded$2e3b7a55-a85b-4498-8dc4-c14853ec06abcell_id$2e3b7a55-a85b-4498-8dc4-c14853ec06abcodemd""" ## Iteration - Reference: [Collections](https://docs.julialang.org/en/v1/base/collections/) For-loops are one of the simplest forms of iteration and can be defined in a number of ways. First, the matlab way: """metadatashow_logsèdisabled®skip_as_script«code_folded$14ab0808-3fdb-4113-8854-43255987a006cell_id$14ab0808-3fdb-4113-8854-43255987a006codec = convert(Float64, 3)metadatashow_logsèdisabled®skip_as_script«code_folded$eacafc14-d0f6-472f-be69-2ab0d81e41b1cell_id$eacafc14-d0f6-472f-be69-2ab0d81e41b1codeTNotebookCard("https://bmlip.github.io/course/minis/Distributions%20in%20Julia.html")metadatashow_logsèdisabled®skip_as_script«code_foldedënotebook_id$6c521516-4560-11f1-9991-1b1093306814in_temp_dir¨metadata